recent

Array of Structures in C

Array of Structures in C

#include<stdio.h>

struct student{

int roll;
char name[20];
int marks[20];
};

main()
{

int i,sum=0;
struct student st;

printf("Enter roll no:\n");
scanf("%d",&st.roll);

printf("Enter name:\n");
scanf("%s",st.name);

printf("Enter Marks:\n");

for(i=0;i<5;i++)
{

scanf("%d",&st.marks[i]);

sum=sum+st.marks[i];

}

printf("Student details:\n\n");

printf("Roll no :%d\n",st.roll);

printf("name :%s\n",st.name);

for(i=0;i<5;i++)
{
printf("%d\n",st.marks[i]);

}

printf("Sum is:%d\n",sum);

}
Powered by Blogger.