Skip to content

Commit 3f757e7

Browse files
committed
renamed from q3
1 parent b20a0e3 commit 3f757e7

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//WAP to input the name of 20 students and arrange them in alphabetical order.
2+
3+
#include <stdio.h>
4+
#include <string.h>
5+
int main(){
6+
char name[20][50], temp[50];
7+
printf("Enter the name of 20 students: ");
8+
for(int i=0; i<20; i++){
9+
scanf("%s", name[i]);
10+
}
11+
for (int i=0; i<20; i++){
12+
for (int j = i+1; j < 20; j++){
13+
if(strcmp(name[i], name[j]) > 0){
14+
strcpy(temp, name[i]);
15+
strcpy(name[i], name[j]);
16+
strcpy(name[j], temp);
17+
}
18+
}
19+
}
20+
printf("Arranged names: \n");
21+
for(int i=0; i<20; i++){
22+
printf("%s\t", name[i]);
23+
}
24+
return 0;
25+
}

0 commit comments

Comments
 (0)