numsort.cpp

来自「some useful programs and simple yet」· C++ 代码 · 共 41 行

CPP
41
字号
#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 + =
减小字号Ctrl + -
显示快捷键?