MUstar

IoT C언어 0710 - EX15_2

Jul 15th, 2017
71
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void swap(char *value, void *num1, void *num2);
  5.  
  6. int main(void)
  7. {
  8.     int age[2];
  9.     double tall[2];
  10.  
  11.     printf("첫 번쨰 사람의 나이와 키 입력 : ");
  12.     scanf("%d%lf",&age[0],&tall[0]);
  13.     printf("두 번째 사람의 나이와 키 입력 : ");
  14.     scanf("%d%lf",&age[1],&tall[1]);
  15.  
  16.     swap("int",&age[0],&age[1]);
  17.     swap("double",&tall[0],&tall[1]);
  18.  
  19.     printf("첫 번쨰 사람의 나이와 키 : %d , %.1lf\n",age[0],tall[0]);
  20.     printf("두 번째 사람의 나이와 키 : %d , %.1lf\n",age[1],tall[1]);
  21.  
  22.     return 0;
  23. }
  24.  
  25. void swap(char *value, void *num1, void *num2)
  26. {
  27.     if(strcmp(value,"int")==0)
  28.     {
  29.         int temp = *(int*)num2;
  30.         *(int*)num2 = *(int*)num1;
  31.         *(int*)num1 = temp;
  32.     }
  33.     else if(strcmp(value,"double")==0)
  34.     {
  35.         double temp = *(double*)num2;
  36.         *(double*)num2 = *(double*)num1;
  37.         *(double*)num1 = temp;
  38.     }
  39. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×