0% found this document useful (0 votes)
4 views3 pages

C Program

In this pdf you will get many questions solutions

Uploaded by

kantistudent1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

C Program

In this pdf you will get many questions solutions

Uploaded by

kantistudent1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#include <stdio.

h>

#include <string.h>

struct student {

char name[60];

int com, math, eng, nep, chem;

} s[100];

int main() {

int n, total;

float percentage;

FILE *fp;

printf("ENTER THE NUMBER OF STUDENTS (1 to 100): ");

scanf("%d", &n);

fp = fopen("[Link]", "w");

for (int i = 0; i < n; i++) {

printf("ENTER %d STUDENT NAME: ", i + 1);

scanf("%s", s[i].name);

printf("ENTER %d MARK OF COMPUTER: ", i + 1);

scanf("%d", &s[i].com);

printf("ENTER %d MARK OF CHEMISTRY: ", i + 1);

scanf("%d", &s[i].chem);
printf("ENTER %d MARK OF MATH: ", i + 1);

scanf("%d", &s[i].math);

printf("ENTER %d MARK OF ENGLISH: ", i + 1);

scanf("%d", &s[i].eng);

printf("ENTER %d MARK OF NEPALI: ", i + 1);

scanf("%d", &s[i].nep);

total = s[i].com + s[i].chem + s[i].math + s[i].eng + s[i].nep;

percentage = ((s[i].com + s[i].chem + s[i].math + s[i].eng + s[i].nep) / 350.0) * 100;

char result[10];

if (s[i].com < 20 || s[i].chem < 27 || s[i].math < 27 || s[i].eng < 27 || s[i].nep < 27) {

strcpy(result, "FAIL");

} else {

strcpy(result, "PASS");

fprintf(fp, "%s %d %d %d %d %d %d %f %s\n", s[i].name, s[i].com, s[i].chem, s[i].math, s[i].eng, s[i].nep,


total, percentage, result);

printf("---------------------------------\n");

fclose(fp);

fp = fopen("[Link]", "r");

printf("\nSTUDENT DETAILS:\n");

printf("NAME\tCOM\tCHEM\tMATH\tENG\tNEP\tTOTAL\tPERCENTAGE\tRESULT\n");

int i = 0;
char result[10]; // Declare result as a string with enough size

while (fscanf(fp, "%s %d %d %d %d %d %d %f %s", s[i].name, &s[i].com, &s[i].chem, &s[i].math, &s[i].eng,


&s[i].nep, &total, &percentage, result) != EOF) {

printf("%s\t%d\t%d\t%d\t%d\t%d\t%d\t%.2f\t%s\n", s[i].name, s[i].com, s[i].chem, s[i].math, s[i].eng,


s[i].nep, total, percentage, result);

i++; // Move to the next student

fclose(fp);

return 0;

You might also like