Write a C program to demonstrate example of structure of array.
#include <stdio.h>
struct student
{
char name [30];
int marks[ 5];
int total;
float perc;
};
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.perc=(float)((float)std.total/(float)500)*100;
printf("\nName: %s \nTotal: %d \nPercentage: %.2f",std.name,std.total,std.perc);
return 0;
}
Output
Enter name: Rahul
Enter marks:
Marks in subject 1 ?: 90
Marks in subject 2 ?: 99
Marks in subject 3 ?: 96
Marks in subject 4 ?: 97
Marks in subject 5 ?: 93
Name: Rahul
Total: 475
Percentage: 95.00