#include <stdio.h>
int main()
{
int a,i,sum=0;
FILE *fp,*fp1; ///file type pointer declared
fp=fopen("input.txt","r"); ///scan file from a text file which you have to create and save data
for(i=0; i<5; i++)
{
fscanf(fp,"%d",&a);
sum+=a; ///add all the elements
}
fclose(fp);
fp1=fopen("output.txt","w"); ///print in text file you don't have to Create this file
fprintf(fp1,"The Sum is :%d",sum);
fclose(fp1);
return 0;
}
Output
1st Step:
You have to Create a text File(name the file as you use in code) and save value
Add your comment