正在加载图片...
计 算 维数组示例二 机 序·使用冒泡法对5个整数按从大到小的顺序排列 设 include <stdio.h> 计 int main0 基 础inti,j,temp static int a[5]={1,712,16,20} for(i=0;i<4;i++) for(=0;j<4-i+){ if(al<a+1)∥若后面数据比前面大则交换 temp=alil; alil=alj+1l; alj+1]=temp for(j=0; j<5; j++)printf("al%od=%dn",j, aljD return 0: 清华大学计算中心 http://learn.tsinghua.edu.cn清华大学计算中心 http://learn.tsinghua.edu.cn 8 计 算 机 程 序 设 计 基 础 一维数组示例二 • 使用冒泡法对5个整数按从大到小的顺序排列 #include <stdio.h> int main() { int i, j, temp; static int a[5] = {1, 7, 12, 16, 20}; for(i = 0; i < 4; i++) for(j = 0; j < 4 – i; j++){ if(a[j] < a[j+1]) // 若后面数据比前面大则交换 { temp = a[j]; a[j] = a[j+1]; a[j+1] = temp; } } for(j = 0; j < 5; j++) printf(“a[%d] = %d\n“, j, a[j]); return 0; }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有