Telaryon

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

Mar 24th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #define N 12
  3. #define TOMB_INICIALIZALAS
  4.  
  5. int main(void){
  6.     int i;
  7.     int db=0;
  8.  
  9. #ifdef TOMB_INICIALIZALAS
  10.     double tomb[]={289.5, 292.6, 290.2, 285.5, 300.4, 300.3, 302.5, 308.3, 303.5, 299.9, 302.3, 305.1};
  11.  
  12. #else
  13.     double tomb[N];
  14.     char karakter;
  15.     int jo;
  16.     int beolvasott_adatok_szama;
  17.  
  18. #endif
  19.     double limit=300.0;
  20.     int monoton;
  21.     int min_index=0;
  22.     int max_index=0;
  23.  
  24.     monoton=1;
  25.  
  26.     printf("HUF/EUR folyamok:\n");
  27.  
  28.     for (i=0; i<N; i++){
  29.  
  30. #ifndef TOMB_INICIALIZALAS
  31.         jo=0;
  32.         do{
  33.             printf("%d. ertek: ", i+1);
  34.             beolvasott_adatok_szama=scanf("%lf", &tomb[i]);
  35.             if (beolvasott_adatok_szama==1)
  36.                 jo=1;
  37.             else{
  38.                 if (beolvasott_adatok_szama==-1)
  39.                     printf("\n");
  40.  
  41.                 printf("Hibas adat. Kerem adja meg ujra!\n");
  42.  
  43.                 if (beolvasott_adatok_szama==0)
  44.                     while ((karakter=getchar())!='\n');
  45.             }
  46.         } while (!jo);
  47. #else
  48.         printf("%d. ertek: %.1lf\n", i+1, tomb[i]);
  49. #endif
  50.         if (tomb[i]<limit)
  51.             db++;
  52.  
  53.         if (i!=0 && tomb[i]<tomb[i-1])
  54.             monoton=0;
  55.  
  56.  
  57.     }
  58.     for(i=1; i<N; i++){
  59.         if(tomb[i]<tomb[min_index]){
  60.             min_index=i;
  61.         }
  62.         if(tomb[i]>tomb[max_index]){
  63.             max_index=i;
  64.         }
  65.     }
  66.     printf("\nAz arfolyam erteke %.1lf Ft alatt volt %d esetben.\n", limit, db);
  67.     printf("\nA sorozat monoton nott? %s", monoton ? "Igaz\n" : "Hamis\n");
  68.     printf("\nA sorozat legkisebb eleme: %.1lf, sorszama: %d\n", tomb[min_index], min_index+1);
  69.     printf("\nA sorozat legnagyobb eleme: %.1lf, sorszama: %d\n\n", tomb[max_index], max_index+1);
  70.  
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment