0% found this document useful (0 votes)
43 views2 pages

N Number Stu Name Roll

The document contains a C program to store and display student name and roll number data using structures. It defines a student structure with roll number and name fields, takes user input for the number of students and a for loop to input each student's roll number and name. It then displays the roll number and name of each student in a formatted table using another for loop.

Uploaded by

Bibek Thapa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views2 pages

N Number Stu Name Roll

The document contains a C program to store and display student name and roll number data using structures. It defines a student structure with roll number and name fields, takes user input for the number of students and a for loop to input each student's roll number and name. It then displays the roll number and name of each student in a formatted table using another for loop.

Uploaded by

Bibek Thapa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

//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);

// inserting rollno and name of students


Prepared By: Ishwar Mahato
for(i=1; i<=n; i++)
{
printf("enter roll number");
scanf("%d",&stu[i].rollno);
printf("enter name");
scanf("%s",stu[i].name);
}
// displaying rollno and name of students
printf(“\nRoll number\t\tname\n”);
for(i=0; i<n; i++)
{
printf(" roll no is=%d \t \tname is =%s \n",stu[i].rollno,stu[i].name);
}
getch();
}

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();
}

Prepared By: Ishwar Mahato

You might also like