#include <stdio.h>
#include <string.h>
#define N 20
int main()
{
int m,n,t,k,i,a,b,flag,j;
int im1,im2,im3,ex1,ex2,ex3;
float ie1,ie2,ie3;
char co1[80], co2[80],co3[80],ch1,ch2;
char country[N][11]={"美国","日本","韩国","德国","越南","澳大利亚","马来西亚","巴西","俄罗斯","泰国",
"印度","印度尼西亚","荷兰","英国","新加坡","沙特阿拉伯","墨西哥","法国","菲律宾","加拿大"};
int import[N]={17970081,20550277,21344326,11991430,9231942,16352908,9830508,11000670,7960907,6183263,
2814551,6392283,1400494,2567686,3881973,5696861,1913928,3910500,2476131,3048978};
int exports[N]={57607523,16581426,14880548,11517540,13789507,6638009,7865488,5361123,6755117,6935458,
9750751,6064749,10243171,8702212,5510346,3032124,6743974,4593066,5151026,5151026};
float IERatio[N];
printf("按进口额从多到少进行冒泡排序后的数据:\n\n");
for(i=0;i<=N-1;i++)
{
IERatio[i]=(float)import[i]/exports[i];
}
printf("%-6s%-13s%-10s%-10s%-10s\n","序号","国家","进口额","出口额","进出口交换比率");
for(m=1;m<N;m++)
{
flag=0;
for(n=0;n<N-1;n++)
{
if(import[n]<import[n+1])
{
im1=import[n];strcpy(co1,country[n]);ex1=exports[n];ie1=IERatio[n];
import[n]=import[n+1];strcpy(country[n],country[n+1]);exports[n]=exports[n+1];IERatio[n]=IERatio[n+1];
import[n+1]=im1;strcpy(country[n+1],co1);exports[n+1]=ex1;IERatio[n+1]=ie1;
flag=1;
}
}
if(flag==0) break;
}
for(a=1;a<=20;a++)
{
printf("%-6d%-13s%-10d%-10d%-10f\n",a,country[a-1],import[a-1],exports[a-1],IERatio[a-1]);
}
printf("\n进口额从多到少进行冒泡排序后的棒图:\n\n") ;
printf("%-6s%-13s%-10s%s%\n","序号","国家","进口额","*号棒");
for(a=1;a<=20;a++)
{
printf("%-6d%-13s%-10d",a,country[a-1],import[a-1]);
b = (int)(import[a-1]* 40.0 /21344326 + 0.5 );
for(;b>0;b--)
{
printf("*");
}
printf("\n");
}
printf("等待键盘输入回车键后进入选择排序\n");
ch1=getch();
if(ch1='\n')
{
printf("\n按出口额由多到少进行选择排序后的数据:\n\n");
printf("%-6s%-13s%-10s%-10s%-10s\n","序号","国家","出口额","进口额","进出口交换比率");
for(n=0;n<N-1;n++)
{
k=n;
for(j=n+1;j<N;j++)
{
if(exports[k]<exports[j])
{
k=j;
}
}
if(k!=n)
{
im2=import[n];strcpy(co2,country[n]);ex2=exports[n];ie2=IERatio[n];
import[n]=import[k];strcpy(country[n],country[k]);exports[n]=exports[k];IERatio[n]=IERatio[k];
import[k]=im2;strcpy(country[k],co2);exports[k]=ex2;IERatio[k]=ie2;
}
}
for(a=1;a<=20;a++)
{
printf("%-6d%-13s%-10d%-10d%-10f\n",a,country[a-1],exports[a-1],import[a-1],IERatio[a-1]);
}
printf("\n出口额由多到少进行选择排序后的棒图:\n\n") ;
printf("%-6s%-13s%-10s%s%\n","序号","国家","出口额","*号棒");
for(a=1;a<=20;a++)
{
printf("%-6d%-13s%-10d",a,country[a-1],exports[a-1]);
b = (int)(exports[a-1]* 40.0 /57607523 + 0.5 );
for(;b>0;b--)
{
printf("*");
}
printf("\n");
}
}
printf("等待键盘输入回车键后进入插入排序\n");
ch2=getch();
if(ch2='\n')
{
printf("\n按进出口交换比率由高到低进行插入排序后的数据:\n\n");
printf("%-6s%-13s%-14s%-10s%-10s\n","序号","国家","进出口交换比率","出口额","进口额");
for(m=1;m<N;m++)
{
ie3=IERatio[m];im3=import[m];strcpy(co3,country[m]);ex3=exports[m];
n=m-1;
while(n>=0&&ie3>IERatio[n])
{
IERatio[n+1]=IERatio[n];import[n+1]=import[n];strcpy(country[n+1],country[n]);exports[n+1]=exports[n];
n--;
}
IERatio[n+1]=ie3;import[n+1]=im3;strcpy(country[n+1],co3);exports[n+1]=ex3;
}
for(a=1;a<=20;a++)
{
printf("%-6d%-13s%-14f%-10d%-10d\n",a,country[a-1],IERatio[a-1],exports[a-1],import[a-1]);
}
printf("\n进出口交换比率由高到低进行插入排序后的棒图:\n\n") ;
printf("%-6s%-13s%-14s%s%\n","序号","国家","进出口交换比率","*号棒");
for(a=1;a<=20;a++)
{
printf("%-6d%-13s%-14d",a,country[a-1],exports[a-1]);
b = (int)(IERatio[a-1]* 40.0 /2.463526 + 0.5 );
for(;b>0;b--)
{
printf("*");
}
printf("\n");
}
}
return 0;
}
0000000
最新推荐文章于 2024-09-08 15:12:17 发布