解题思路:这个解法用了较多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 人评分
点我有惊喜!你懂得!浏览:2072 |
陶陶摘苹果 (C语言代码)浏览:1607 |
小九九 (C语言代码)浏览:825 |
C语言程序设计教程(第三版)课后习题3.7 (C++代码)浏览:998 |
C语言训练-角谷猜想 (C++代码)(3N+1问题)浏览:1751 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:1121 |
C语言训练-字符串正反连接 (C语言代码)浏览:622 |
【简单计算】 (C语言代码)浏览:622 |
WU-图形输出 (C++代码)浏览:802 |
字符逆序 (C语言代码)浏览:617 |