📄 numsort.cpp
字号:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define N 5
// This program sort a given list of name and scores by score.
// Morteza Zafari 2001
void main()
{
clrscr();
char name[N][20],tmpstr[20];
float score[N],tmpscr;
int i,j,c=0;
printf("\n This program sort a given list of name and scores by score.\n");
for (i=0;i<N;i++){
printf("\n Enter name No %d: ",i+1);
gets(name[i]);
printf("\n Enter name %s's score: ",name[i]);
scanf("%f",score[i]);
}
for (i=0;i<N;i++){
for (j=0;j<N;j++){
if (score[c+1]<=score[c]){
strcpy(tmpstr,name[c]);
strcpy(name[c],name[c+1]);
strcpy(name[c+1],tmpstr);
tmpscr=score[c];
score[c]=score[c+1];
score[c+1]=tmpscr;
}
c++;
}
c=0;
}
for (i=0;i<N;i++){
printf("\n Name No %d: ",i+1);
puts(name[i]);
}
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -