N Number Stu Name Roll
N Number Stu Name Roll
//program to store name and rollno of n students and display using structure in proper format
#include<stdio.h>
#include<conio.h>
struct student
{
int rollno;
char name[20];
};
int main()
{
int n,i;
printf("enter value of n");
scanf("%d",&n);
struct student stu[n];
// inserting roll number and name of students
for(i=0;i<n;i++)
{
printf("enter roll number");
scanf("%d",&stu[i].rollno);
printf("enter name ");
scanf("%s",stu[i].name);
}
//displaying roll number and name of students
printf("\nRollno\t\tname\n");
for(i=0;i<n;i++)
{
printf("%d\t\t%s\n",stu[i].rollno,stu[i].name);
}
getch();
}
Alternative:
#include<stdio.h>
#include<conio.h>
struct student
{
int rollno;
char name[20];
} stu[100];
int main()
{
int n,i,j;
printf("enter value of n");
scanf("%d",&n);
Alternative:
#include<stdio.h>
#include<conio.h>
int main()
{ int n,i;
printf("enter value of n");
scanf("%d",&n);
struct student
{
int rollno;
char name[20];
} stu[n];
// inserting roll number and name of students
for(i=0;i<n;i++)
{
printf("enter roll number");
scanf("%d",&stu[i].rollno);
printf("enter name ");
scanf("%s",stu[i].name);
}
//displaying roll number and name of students
printf("\nRollno\t\tname\n");
for(i=0;i<n;i++)
{
printf("%d\t\t%s\n",stu[i].rollno,stu[i].name);
}
getch();
}