?? 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 + -