0% found this document useful (0 votes)
36 views

Practical 1 Structures

This program accepts information (name, roll number, marks) for 3 students and stores it in a structure. It then sorts the student records by ascending roll number using a nested for loop. Finally, it displays the sorted student information by name, roll number and marks.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Practical 1 Structures

This program accepts information (name, roll number, marks) for 3 students and stores it in a structure. It then sorts the student records by ascending roll number using a nested for loop. Finally, it displays the sorted student information by name, roll number and marks.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Practical1

Aim: Write a program in C which accepts information of ten students & display the same
information according to ascending order of their roll numbers using structures.


#include <conio.h>
#include <string.h>
#include <stdio.h>
void main()
{
struct student
{
char name[20];
int roll;
int marks;
};
struct student s[3],temp;
int i,j;
clrscr();
for(i=0;i<=2;i++)
{
printf("enter the name,roll no.,marks");
//gets(s[i].name);
scanf("%s%d%d",s[i].name,&s[i].roll,&s[i].marks);
}
for(i=0;i<=2;i++)
{
for(j=i+1;j<=2;j++)
{
if(s[i].roll > s[j].roll)
{
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
}
for(i=0;i<3;i++)
{
printf("%s %d %d", s[i].name,s[i].roll,s[i].marks);
}
getch();
}

You might also like