belongs to collection: All structure C programs with examples
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; }
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
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.
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