C Program for writing data to a file

#include<stdio.h>

#include<conio.h>

int main()
{
FILE *fp;
int n1,n2,sum;
printf(“Enter two numbers: “);
scanf(“%d%d”,&n1,&n2);
sum=n1+n2;
printf(“Sum of numbers = %d”,sum);
fp=fopen(“data.txt”,”w”);
fprintf(fp,”%d %d %d”,n1,n2,sum);
fclose(fp);
getch();
return 0;
}

Output

C Program for writing to a file

Published by

admin

I am a computer teacher, programmer and web developer