• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

cxr119911

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

No.13 成绩排序

#include "stdio.h"
#include "stdlib.h"
void px(float score1[],long int num1[],int n1);
void main()
{int i,n;
float score[50];
long int num[50];
printf("Input n:\n");
scanf("%d",&n);
printf("Input num & score:\n");
for(i=0;i<n;i++)
{scanf("%ld,%f",&num[i],&score[i]);}
px(score,num,n);
printf("PX jieguo:\n");
for(i=0;i<n;i++)
{printf("%ld,%2f\n",num[i],score[i]);}
system("pause");
}
void px(float score1[],long int num1[],int n1)
{int i1,j1;
float temp1;
long int temp2;
for(i1=0;i1<n1;i1++)
{for(j1=i1+1;j1<n1;j1++)
{if(score1[j1]>score1[i1])
{temp1=score1[i1];
score1[i1]=score1[j1];
score1[j1]=temp1;
temp2=num1[i1];
num1[i1]=num1[j1];
num1[j1]=temp2;}
}
}
}

 

1.冒泡排序的内、外循环问题回来还得看;

2.注意数组是score[],不是score(),也不是score;

3.%8.3f:有效数字8位,小数点后2位。

 

posted on 2016-12-03 20:51  cxr119911  阅读(124)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3