Student details(structure-for loop)

C program to display student details :

code

#include<stdio.h>
#include<conio.h>
struct stud
{
int roll_no;
char name[50];
char dept[50];
};

void main()
{
struct stud s[10];
int i,size;
clrscr();
printf(“Enter number of student to insert their details :”);
scanf(“%d”,&size);
for(i=0;i<size;i++)
{

printf(“\nEnter roll number of student :”);
scanf(“%d”,&s[i].roll_no);
printf(“\nEnter student name :”);
scanf(“%s”,s[i].name);
printf(“\nEnter department  name :”);
scanf(“%s”,s[i].dept);

}

printf(“\nStudent details :”);
printf(“\nRoll_no\t\tName\t\t department”);

for(i=0;i<size;i++)
{
printf(“\n%d”,s[i].roll_no);
printf(“\t\t%s”,s[i].name);
printf(“\t\t%s”,s[i].dept);
}
getch();
}

 


output

Enter number of student to insert their details :2

Enter roll number of student :1

Enter student name :raj

Enter department  name :computer

Enter roll number of student :2

Enter student name :rohit

Enter department  name :civil

Student details :

Roll_no                 name                 department

1                                raj                       computer

2                                rohit                     civil

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s