SEQUENTIAL ALGORITHM
#include <stdio.h>
struct file
{
int regno,marks1,marks2,marks3;
char name[10];
};
main()
{
FILE *fp;
float avg;
int i,n,total;
struct file x[30];
clrscr();
printf("Enter no. of students: ");
scanf("%d", &n);
fp=fopen("Student.txt","w");
printf("input student list data \n\n");
for(i=1;i<=n;i++)
{
printf("Reg.N0 Name Marks1 Marks2 Marks3\n");
fscanf(stdin,"%d%s%d%d%d",&x[i].regno,x[i].name,
&x[i].marks1,&x[i].marks2,&x[i].marks3);
fprintf(fp,"%d\t%s\t%d\t%d\t%d\t\n",x[i].regno,
x[i].name,x[i].marks1,x[i].marks2,x[i].marks3);
}
fclose(fp);
fprintf(stdout,"\n\n");
fp=fopen("student.txt","r");
printf("Regno Name Marks1 Marks2 Marks3 Total Avg\n");
for(i=1;i<=n;i++)
{
total= x[i].marks1+x[i].marks2+x[i].marks3;
avg=(float)total/3;
printf("%d\t%s\t%d\t%d\t%d\t%d\t%f\n",x[i].regno,x[i].name,x[i].marks1,
x[i].marks2,x[i].marks3,total,avg);
}
fclose(fp);
getch();
}
No comments:
Post a Comment