Advertisement
zagdon

Untitled

Dec 11th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | None | 0 0
  1.  #include <stdio.h>
  2.  #include <stdlib.h>
  3.  
  4. int Pontszamok[20] = {18, 15, 12, 25, 25, 15, 10, 25, 0, 18 };
  5. int PontszamGyakorisag[26];
  6.  
  7. void Init()
  8. {
  9.  
  10.     for (int i = 10; i < 20; i++) {
  11.         printf("add meg a %d futam pontszamat\n", i + 1);
  12.         scanf("%d", &Pontszamok[i]);
  13.     }
  14. }
  15.  
  16. void CalcPontszamGyakorisag()
  17. {
  18.     //reset
  19.     for (int i = 0; i <=25; i++)
  20.     {
  21.         PontszamGyakorisag[i] = 0;
  22.     }
  23.  
  24.     //szamolas
  25.     for (int i = 0; i <=25; i++)
  26.     {
  27.         PontszamGyakorisag[Pontszamok[i]] += 1;
  28.     }
  29.  
  30.     //kiiras
  31.     for (int i = 0; i <=25; i++)
  32.     {
  33.         if (PontszamGyakorisag[i] > 0)
  34.         {
  35.             printf("%d pont ennyiszer lett elerve: %d\n", i, PontszamGyakorisag[i]);
  36.         }
  37.     }
  38. }
  39.  
  40. void CalcStats()
  41. {
  42.     int sum = 0;
  43.     int max = Pontszamok[0];
  44.     int min = Pontszamok[0];
  45.  
  46.     for (int i = 0; i < 20; i++) {
  47.  
  48.         sum += Pontszamok[i];
  49.  
  50.         if (Pontszamok[i] > max) {
  51.             max = Pontszamok[i];
  52.         }
  53.  
  54.         if (Pontszamok[i] < min) {
  55.             min = Pontszamok[i];
  56.         }
  57.     }
  58.  
  59.     printf("sum: %d\n", sum);
  60.     printf("max: %d\n", max);
  61.     printf("min: %d\n", min);
  62.     printf("atlag: %.2f\n", (double)sum / 20);
  63. }
  64.  
  65.  int main ()
  66.  {
  67.     Init();
  68.     CalcStats();
  69.     CalcPontszamGyakorisag();
  70.     return 0;
  71.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement