Guest User

Untitled

a guest
Jul 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int szamok[10];
  5. int sum=0;
  6. int x=0;
  7. int avg;
  8. int j;
  9. int ln;
  10. int lk;
  11.  
  12. int osszeg(int x)
  13. {
  14.     for(j=1;j<x;j++)
  15.         {
  16.             sum=sum+szamok[j];
  17.         }
  18.     return sum;
  19.  
  20. }
  21.  
  22. double atlag(int x)
  23. {
  24.  
  25.     for(j=1;j<11;j++)
  26.         {
  27.             avg=avg+szamok[j];
  28.  
  29.         }
  30.  
  31.     return avg/x;
  32. }
  33.  
  34. int legn(int x)
  35. {
  36.     int ln=szamok[0];
  37.     for(j=1;j<x;j++)
  38.         {
  39.             if(szamok[j]>ln)
  40.                 {
  41.                     ln=szamok[j];
  42.                 }
  43.  
  44.        }
  45. return ln;
  46.  
  47. }
  48. int legk(int x)
  49. {
  50.     int lk=szamok[0];
  51.     for(j=1;j<x;j++)
  52.         {
  53.             if(szamok[j]<lk)
  54.                 {
  55.                     lk=szamok[j];
  56.                 }
  57.  
  58.         }
  59.     return lk;
  60. }
  61.  
  62. int main()
  63. {
  64.     FILE * input;
  65.     FILE * output;
  66.     input=fopen("input.txt","r");
  67.     while(!feof(input))
  68.         {
  69.             fscanf(input,"%d",&szamok[x]);
  70.         }
  71.     output=fopen("output.txt","w");
  72.     fprintf(output,"%d %d %d %lf",legk(x),legn(x),osszeg(x),atlag(x));
  73.     fclose(input);
  74.     fclose(output);
  75.  
  76.     return 0;
  77. }
Add Comment
Please, Sign In to add comment