Program To Read File Containing Rollno, Name, Marks of Three Subjects and Calculate Total Marks, Result in Grade and Store in File
Program To Read File Containing Rollno, Name, Marks of Three Subjects and Calculate Total Marks, Result in Grade and Store in File
Program To Read File Containing Rollno, Name, Marks of Three Subjects and Calculate Total Marks, Result in Grade and Store in File
#include<stdio.h>
#include<conio.h>
int k=0;
struct stud
int rn;
char name[30];
int m1,m2,m3,total;
float avg;
char grade,result;
s[30];
void main()
int no,roll=101,i;
FILE *fptr;
clrscr();
printf("Enter NO of Students:");
scanf("%d",&no);
fptr=(fopen("C:\\student.txt","w"));
if(fptr==NULL) {
printf("Error!");
exit(1);
for(i=0;i<no;i++)
clrscr();
s[k].rn=roll;
fflush(stdin);
gets(s[k].name);
scanf("%d",&s[k].m1);
scanf("%d",&s[k].m2);
scanf("%d",&s[k].m3);
s[k].result='P';
else
s[k].result = 'F';
s[k].total = s[k].m1+s[k].m2+s[k].m3;
s[k].avg=s[k].total/3;
if(s[k].avg>=60)
if(s[k].result == 'P')
s[k].grade = 'A';
else
s[k].grade = 'N';
else if(s[k].avg>=50)
if(s[k].result == 'P')
s[k].grade = 'B';
else
s[k].grade = 'N';
else if(s[k].avg>=35)
if(s[k].result == 'P')
{
s[k].grade = 'C';
else
s[k].grade = 'N';
getch();
k++;
roll++;
printf("\n*******************************************************");
printf("\n*******************************************************");
for(i=0;i<no;i++)
printf("\n%d\t%s %d %d %d %d %c %0.1f
%c",s[i].rn,s[i].name,s[i].m1,s[i].m2,s[i].m3,s[i].total,s[i].result,s[i].avg,s[i].grade);
fclose(fptr);
getch();
}
Program to read electricity previous meter reading,current meter reading and total units with rate
calculation and writing it to a file
#include <stdio.h>
#include <conio.h>
void main()
int previousreading;
int currentreading;
int unit;
int amount;
FILE *fptr;
clrscr();
scanf("%d" ,&previousreading);
scanf("%d" ,¤treading);
fptr=(fopen("C:\\reading.txt","w"));
if(fptr==NULL) {
printf("Error!");
exit(1);
if(unit<=50)
{
amount = unit * 1;
else if(unit>100)
amount = unit * 2;
fclose(fptr);
getch();
Program to read no of words in a each sentence and display no of words and sentence and compute
average no of words per sentence
#include<stdio.h>
#include<conio.h>
void main()
FILE *p;
char ch;
int w=1;
clrscr();
p=fopen("c:\\RESULT.txt","r");
if(p==NULL)
else
ch=fgetc(p);
while(ch!=EOF)
printf("%c",ch);
if(ch==' '||ch=='\n')
w++;
ch=fgetc(p);
fclose(p);
getch();
Program to read Student Marks, Rollno, Name and grades and store only failed result in a file
#include <stdio.h>
#include <conio.h>
int main(){
int num,rollno;
char name[30];
FILE *fptr;
clrscr();
scanf("%s",&name);
scanf("%d",&rollno);
scanf("%d",&num);
fptr=(fopen("C:\\failed.txt","w"));
if(fptr==NULL) {
printf("Error!");
exit(1);
}
else if ( num >=40){
fclose(fptr);
getch();
return 0;