解题思路:这个解法用了较多for循环,属于一个比较死板但易懂的方法
注意事项:一个for循环只能给十个数最多分别调动一个位置,由此得出十个相同的for循环可以达到如题所述的效果,话不多说,上代码
参考代码:
#include<stdio.h>
int main(void)
{
int ten[10],x,i,n;
for (i=0;i<10;i++)
{
scanf("%d",&ten[i]);
}
for (i=0;i<10;i++)
{
if (ten[i]>ten[i+1])
{
n=ten[i];
ten[i]=ten[i+1];
ten[i+1]=n;
}
}
for (i=0;i<10;i++)
{
if (ten[i]>ten[i+1])
{
n=ten[i];
ten[i]=ten[i+1];
ten[i+1]=n;
}
}
for (i=0;i<10;i++)
{
if (ten[i]>ten[i+1])
{
n=ten[i];
ten[i]=ten[i+1];
ten[i+1]=n;
}
}
for (i=0;i<10;i++)
{
if (ten[i]>ten[i+1])
{
n=ten[i];
ten[i]=ten[i+1];
ten[i+1]=n;
}
}
for (i=0;i<10;i++)
{
if (ten[i]>ten[i+1])
{
n=ten[i];
ten[i]=ten[i+1];
ten[i+1]=n;
}
}
for (i=0;i<10;i++)
{
if (ten[i]>ten[i+1])
{
n=ten[i];
ten[i]=ten[i+1];
ten[i+1]=n;
}
}
for (i=0;i<10;i++)
{
if (ten[i]>ten[i+1])
{
n=ten[i];
ten[i]=ten[i+1];
ten[i+1]=n;
}
}
for (i=0;i<10;i++)
{
if (ten[i]>ten[i+1])
{
n=ten[i];
ten[i]=ten[i+1];
ten[i+1]=n;
}
}
for (i=0;i<10;i++)
{
if (ten[i]>ten[i+1])
{
n=ten[i];
ten[i]=ten[i+1];
ten[i+1]=n;
}
}
for (i=0;i<10;i++)
{
if (ten[i]>ten[i+1])
{
n=ten[i];
ten[i]=ten[i+1];
ten[i+1]=n;
}
}
for (i=0;i<10;i++)
{
printf("%d\n",ten[i]);
}
return 0;
}
0.0分
0 人评分
众数问题 (C语言代码)浏览:3515 |
C二级辅导-分段函数 (C语言代码)浏览:566 |
永远的丰碑 (C语言代码)浏览:656 |
C语言程序设计教程(第三版)课后习题10.5 (C语言代码)浏览:733 |
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:581 |
九宫重排 (C++代码)浏览:2160 |
P1001 (C语言代码)浏览:801 |
简单的a+b (C语言代码)浏览:340 |
C语言训练-求1+2!+3!+...+N!的和 (C语言代码)浏览:790 |
2005年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:648 |