Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // textfiles.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "iostream";
- using namespace std;
- void main() {
- FILE *fp=NULL;
- int x;
- int max=0,min=1000000;
- int sum=0;
- fopen_s (&fp,"D:\\tareq.txt","w+");
- if (fp==NULL)
- cout<<"cannot open file";
- else
- {
- for (int i=1 ; i<=20 ; i++ )
- {
- cin>>x;
- if (x>=max)
- max=x;
- if (x<min)
- min=x;
- sum=sum+x;
- fprintf(fp , "%d\n",x);
- }
- }
- sum=sum/20;
- //***************************************************
- FILE *fp1=NULL;
- fopen_s (&fp,"D:\\tareq1.txt","w+");
- fprintf(fp , "Max= %d\n",max);
- fprintf(fp , "min= %d\n",min);
- fprintf(fp , "avg= %d\n",sum);
- //**************************************************
- rewind(fp);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement