Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. // textfiles.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "iostream";
  6. using namespace std;
  7. void main() {
  8. FILE *fp=NULL;
  9. int x;
  10. int max=0,min=1000000;
  11. int sum=0;
  12. fopen_s (&fp,"D:\\tareq.txt","w+");
  13. if (fp==NULL)
  14. cout<<"cannot open file";
  15. else
  16. {
  17. for (int i=1 ; i<=20 ; i++ )
  18. {
  19. cin>>x;
  20. if (x>=max)
  21. max=x;
  22. if (x<min)
  23. min=x;
  24. sum=sum+x;
  25. fprintf(fp , "%d\n",x);
  26. }
  27. }
  28. sum=sum/20;
  29. //***************************************************
  30. FILE *fp1=NULL;
  31. fopen_s (&fp,"D:\\tareq1.txt","w+");
  32. fprintf(fp , "Max= %d\n",max);
  33. fprintf(fp , "min= %d\n",min);
  34. fprintf(fp , "avg= %d\n",sum);
  35. //**************************************************
  36. rewind(fp);
  37.  
  38.  
  39. system("pause");
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement