📄 p2.c
字号:
/*
WAPto enter the name of ten student and roll number and then arrange
them alphabatically and then by roll no and print the name of the
student whose position is same after sorting*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int a,i,j;
char n[10][50],c[10][50],t[50];
long nr[10],tr,cr[10];
clrscr();
printf("how many number of students you want to enter: ");
scanf("%d",&a);
for(i=0;i<a;i++)
{
printf("Enter the %d name: ",i+1);
fflush(stdin);
gets(n[i]);
printf("Enter the Roll No:");
scanf("%ld",&nr[i]);
}
printf("\n\nName\t\tRoll number");
for(i=0;i<a;i++)
{
printf("\n%s\t\t%ld",n[i],nr[i]);
}
for(j=0;j<a;j++)
{
strcpy(t,n[j]);
for(i=j+1;i<a;i++)
{
if(strcmp(t,n[i])>0)
{
strcpy(t,n[i]);
tr=nr[i];
strcpy(n[i],n[j]);
nr[i]=nr[j];
strcpy(n[j],t);
nr[j]=tr;
}
}
}
printf("\nNames after sorting alphabatically");
printf("\n\nName\t\tRoll number");
for(i=0;i<a;i++)
{
printf("\n%s\t\t%ld",n[i],nr[i]);
}
getch();
for(i=0;i<a;i++)
{
cr[i]=nr[i];
strcpy(c[i],n[i]);
}
for(i=0;i<a;i++)
{
tr=cr[i];
for(j=i+1;j<a;j++)
{
if(tr>cr[j])
{
tr=cr[j];
strcpy(t,c[j]);
cr[j]=cr[i];
strcpy(c[j],c[i]);
cr[i]=tr;
strcpy(c[i],t);
}
}
}
printf("\n Name after sorting by roll numbers");
printf("\n\nName\t\tRoll number");
for(i=0;i<a;i++)
{
printf("\n%s\t\t%ld",c[i],cr[i]);
}
getch();
printf("\n\nName\t\tRoll number");
i=0;
for(i=0;i<a;i++)
{
if(strcmp(c[i],n[i])==0)
printf("\n%s\t\t%ld",n[i],cr[i]);
}
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -