Q:

Write a C program to calculate percentage of student using structure

0

Write a C program to calculate percentage of student using structure

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.

#include <stdio.h>
 
struct student
{
    char name [30];
    int  marks[ 5];
    int  total;
    float percentage;
};
 
int main()
{
    struct student std;
    int i;
 
    printf("Enter name: ");
    gets(std.name);
 
    printf("Enter marks:\n");
    std.total=0;
    for(i=0;i< 5;i++){
        printf("Marks in subject %d: ",i+1);
        scanf("%d",&std.marks[i]);
        std.total+=std.marks[i];
    }
    std.percentage=(float)((float)std.total/(float)500)*100;
 
    printf("\nName: %s \nTotal Marks: %d \nPercentage: %.2f",std.name,std.total,std.percentage);
 
    return 0;
}

Result:

Enter name: John

Enter marks:

Marks in subject 1: 80

Marks in subject 2: 90

Marks in subject 3: 70

Marks in subject 4: 60

Marks in subject 5: 85

Name: John 

Total Marks: 385 

Percentage: 77.00

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a C program to create Book Details using str... >>
<< Write a C program to demonstrate example of struct...