Q36 Write a C program to demonstrate example of structure of array.

Admin

 

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

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.