1.
A program to store information of a students and display
it
#include<stdio.h>
struct student
{
char name[10];
int rollno;
float marks;
}s;
main ( )
{
printf("enter the information\n");
printf("enter the name\n");
scanf("%s",s.name);
printf("enter the roll number\n");
scanf("%d",&s.rollno);
printf("enter the marks\n");
scanf("%f",&s.marks);
printf("Diplay information: \n");
printf("name: " );
puts(s.name);
printf("roll number: %d\n", s.rollno);
printf("marks: %f\n", s.marks);
}
Output
enter the name
fgfg
enter the roll number
2
enter the marks
56
Diplay information:
name: fgfg
roll number: 2
marks: 56.000000
1.A program to find the total marks of n students
#include<stdio.h>
struct student
{
char name[10];
int rollno;
int subject[5],total;
};
main ( )
{
static struct student s[100];
int n,i,j;
printf("enter the no.of students\n");
scanf("%d",&n);
//printf("enter the marks of five subjects\n");
for(i=0;i<n;i++)
{
printf("enter student roll number \n");
scanf("%d",&s[i].rollno);
printf("enter student name \n");
scanf("%s", s[i].name);
printf("enter s[%d] student marks\n",i);
s[i].total=0;
for(j=0;j<5;j++)
{
scanf("%d",&s[i].subject[j]);
s[i].total=s[i].total+s[i].subject[j];
}
printf("%d\t%s\t%d\n",s[i].rollno,s[i].name,s[i].total);
}
}
Output
enter the no.of students 2
enter student roll number
1
enter student name
anu
enter s[0] student marks
1
2
3
4
5
1 anu 15
enter student roll number
2
enter student name
akhil
enter s[1] student marks
12
32
14
15
65
2 akhil 138