Program to maintain student details using structures
Program:
#include<stdio.h>
#include<conio.h>
struct stud
{
int rollno, s1, s2, tot;
char name[10];
float avg;
} s[10];
void main()
{
int i, n;
clrscr();
printf("Enter the number of students : ");
scanf("%d", &n);
for(i = 0; i < n; i++)
{
printf("\nEnter the roll number : ");
scanf("%d", &s[i].rollno);
printf("\nEnter the name : ");
scanf("%s", s[i].name);
printf("\nEnter the marks in 2 subjects : ");
scanf("%d %d", &s[i].s1, &s[i].s2);
s[i].tot = s[i].s1 + s[i].s2;
s[i].avg = s[i].tot / 2.0;
}
printf("\nRoll No. Name \t\tSub1\t Sub2\t Total\t Average\n\n");
for(i = 0; i < n; i++)
{
printf("%d \t %s \t\t %d \t %d \t %d \t %.2f \n", s[i].rollno,s[i].name,s[i].s1,s[i].s2,s[i].tot,s[i].avg);
}
getch();
}
Output:
Enter the number of students : 2
Enter the roll number : 101
Enter the name : Arun
Enter the marks in 2 subjects : 75 85
Enter the roll number : 102
Enter the name : Babu
Enter the marks in 2 subjects : 65 75
Roll No. Name Sub1 Sub2 Total Average
101 Arun 75 85 160 80.00
102 Babu 65 75 140 70.00
-
UpdatedDec 31, 2019
-
Views95,437
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order