Telaryon

Példa előfordítói direktívák használatára II.

Mar 24th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. #define N 12
  6. #define VERZIO 1
  7.  
  8. int main(void){
  9.     int i;
  10.     double tomb[N];
  11.     double *mutato;
  12.     double atlag=0;
  13.  
  14.     printf("HUF/EUR folyamok:\n");
  15.     srand(time(NULL));
  16.    
  17.     for (i=0; i<N; i++){
  18.         tomb[i]=rand()%31+280;
  19.         atlag+=tomb[i];
  20.         printf("%2d. ertek: %.1lf\n", i + 1, tomb[i]);
  21.     }
  22.     atlag /= N;
  23.     printf("\nAz atlag: %.3f\n", atlag);
  24.  
  25. #if VERZIO == 1
  26.     for(i=0; i<N; i++){
  27.         printf("%d. \t %.1lf \t %6.2lf\n", i+1, tomb[i], tomb[i] - atlag);
  28.     }
  29.  
  30. #elif VERZIO == 2
  31.         for (mutato=tomb, i=0; i<N; i++)
  32.         printf("%d. \t %.1lf \t %6.2lf\n", i + 1, *(mutato + i), mutato[i] - atlag);
  33.  
  34. #elif VERZIO == 3
  35.         for (mutato=tomb, i=0; mutato <= &tomb[N-1]; i++, mutato++)
  36.         printf("%d. \t %.1lf \t %6.2lf\n", i + 1, *mutato, *mutato - atlag);
  37.        
  38. #else
  39.         for (mutato=tomb; mutato <= &tomb[N-1]; mutato++)
  40.                 printf("%d. \t %.1lf \t %6.2lf\n", mutato - tomb + 1, *mutato, *mutato - atlag);
  41. #endif
  42.  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment