Write a C program to calculate percentage of student using structure

Introduction

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

Write a C program to calculate percentage of student using structure
Write a C program to calculate percentage of student using structure

 

Leave a Comment