A program to explain how to use a struct
C Programming Language 089
- Write a program to explain how to use a struct
- Program to read student structure with student name, roll number, six subject marks and find the average
Program
#include <stdio.h>
struct student
{
char name[15];
int rn, m1, m2, m3, m4, m5, m6, tot;
float avg;
};
void main()
{
struct student s;
printf("Enter name and roll number:\n");
scanf("%s %d", &s.name, &s.rn);
printf("Enter six subjects marks:\n");
scanf("%d %d %d %d %d %d", &s.m1, &s.m2, &s.m3, &s.m4, &s.m5, &s.m6);
s.tot = s.m1 + s.m2 + s.m3 + s.m4 + s.m5 + s.m6;
s.avg = s.tot / 6.0;
printf("Average = %f", s.avg);
printf("\n");
}
Result
Enter name and roll number:
John 123
Enter six subjects marks:
90 92 93 87 89 90
Average = 90.166664
Last Updated on
Comments