Write a program which generates the table of a number given by user and then write
the table in a file named “table.dat”.
#include <stdio.h>
int main()
{
int n;
printf("Enter a number: ");
scanf("%d", &n);
FILE *fptr;
fptr = fopen("table.dat","w");
if(fptr == NULL)
{
printf("Error!");
}
fprintf(fptr,"%d",n);
for(int i=1;i<=12;i++){
int m=i*n;
fprintf(fptr,"%d x %d = %d \n",i,n,m);
}
fclose(fptr);
return 0;
}
Comments
Leave a comment