C++ 冒泡算法 练习
2008-06-05 23:00
267 查看
#include "stdio.h"
void main()
{
int array[5],temp;
printf("输入五个数字:\n");
for (int t=0;t<5;t++)
{
scanf("%d",&array[t]);
}
//printf("输出的数字%d\n",array[j]);
for (int j=0; j<5;j++)
for (int i=0;i<5-j;i++)
if (array[i]>array[i+1])// 第一个大于第二个的时候
{
temp=array[i];
array[i]=array[i+1];
array[i+1]=temp;
}
printf("冒泡排序的算法是");
for (int i=0;i<5;i++)
{
printf("%d",array[i]);
}
}
void main()
{
int array[5],temp;
printf("输入五个数字:\n");
for (int t=0;t<5;t++)
{
scanf("%d",&array[t]);
}
//printf("输出的数字%d\n",array[j]);
for (int j=0; j<5;j++)
for (int i=0;i<5-j;i++)
if (array[i]>array[i+1])// 第一个大于第二个的时候
{
temp=array[i];
array[i]=array[i+1];
array[i+1]=temp;
}
printf("冒泡排序的算法是");
for (int i=0;i<5;i++)
{
printf("%d",array[i]);
}
}
相关文章推荐
- C++ 冒泡算法 练习
- C++ 冒泡算法 练习
- C++ 练习错题总结
- C++primer plus第六版课后编程练习答案13.1
- 冒泡算法(C++模板实现)
- C++原型设计模式小练习
- 《C++ Primer Plus (第6版)》5.9 编程练习
- c++ primer plus(第6版)中文版 第五章编程练习答案
- C++ Primer Plus第六版编程练习6.7解答
- C++ Primer Plus(第六版)第四章编程练习参考答案
- c++ primer plus 第六章变成练习 第7题
- C++ Primer Plus 编程练习 第四章
- 【牛客带你学编程C++方向】项目练习第1期
- 【LeetCode012算法/编程练习C++】Integer to Roman //map的遍历&数组的妙用
- c++ primer plus(第6版)中文版 第八章编程练习答案
- 【LeetCode013算法/编程练习C++】Roman to Integer //难得击败了80%的人
- c++ primer plus(第6版)中文版 第九章编程练习答案
- C++ primer plus(sixth edition) 编程练习答案(answers for programing exercises)第七章(chapter 7) 1-5
- 【LeetCode算法练习(C++)】Container With Most Water
- C++文件练习