Program to illustrate n number of students records using structure
#include <stdio.h>
struct student
{
// defining a structure
char name[33];
int sno,sub1,sub2;
float tot;
} s[11];
int main()
{
int i,n;
printf("\n Enter the number of students information :");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("\n Enter student number :");
scanf("%d",&s[i].sno);
printf("\n Enter student name :");
scanf("%s",s[i].name);
printf("\n Enter student mark in subject1 :");
scanf("%d",&s[i].sub1);
printf("\n Enter student mark in subject2 :");
scanf("%d",&s[i].sub2);
}
printf("\n **** Student Details **** :");
printf("\n SNO --- SNAME --- SUB1 --- SUB2 --- TOTAL");
for(i=1;i<=n;i++)
{
s[i].tot = s[i].sub1 + s[i].sub2;
printf("\n %d --- %s --- %d --- %d --- %f ",s[i].sno,s[i].name,s[i].sub1,s[i].sub2,s[i].tot);
}
return 0;
}
output:
#include <stdio.h>
struct student
{
// defining a structure
char name[33];
int sno,sub1,sub2;
float tot;
} s[11];
int main()
{
int i,n;
printf("\n Enter the number of students information :");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("\n Enter student number :");
scanf("%d",&s[i].sno);
printf("\n Enter student name :");
scanf("%s",s[i].name);
printf("\n Enter student mark in subject1 :");
scanf("%d",&s[i].sub1);
printf("\n Enter student mark in subject2 :");
scanf("%d",&s[i].sub2);
}
printf("\n **** Student Details **** :");
printf("\n SNO --- SNAME --- SUB1 --- SUB2 --- TOTAL");
for(i=1;i<=n;i++)
{
s[i].tot = s[i].sub1 + s[i].sub2;
printf("\n %d --- %s --- %d --- %d --- %f ",s[i].sno,s[i].name,s[i].sub1,s[i].sub2,s[i].tot);
}
return 0;
}
output:
No comments:
Post a Comment