一道c语言程序题请求高手帮忙!

需要一段C程序,其功能要包含3点:1、当输入一个数(不超过5位数)时,要判断它是几位数;2、能把这几个数拆开显示出来;3、把这几位数按从小到大顺序排列。例如:输入543;... 需要一段C程序,其功能要包含3点:
1、当输入一个数(不超过5位数)时,要判断它是几位数;
2、能把这几个数拆开显示出来;
3、把这几位数按从小到大顺序排列。
例如:输入543;
显示“这个数为三位数”;
显示“这个数由数字“5.4.3”组成”;
显示“3;4;5”.

谢谢高手帮忙呀!!!!
展开
 我来答
代码小猪
2009-03-29 · TA获得超过288个赞
知道答主
回答量:15
采纳率:0%
帮助的人:22.7万
展开全部
题目:给一个不多于5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字。
1. 程序分析:学会分解出每一位数,如下解释:(这里是一种简单的算法)
2.程序源代码:
#include "stdio.h"
#include "conio.h"
main( )
{
long a,b,c,d,e,x;
scanf("%ld",&x);
a=x/10000;/*分解出万位*/
b=x%10000/1000;/*分解出千位*/
c=x%1000/100;/*分解出百位*/
d=x%100/10;/*分解出十位*/
e=x%10;/*分解出个位*/
if (a!=0) printf("there are 5, %ld %ld %ld %ld %ld\n",e,d,c,b,a);
else if (b!=0) printf("there are 4, %ld %ld %ld %ld\n",e,d,c,b);
else if (c!=0) printf(" there are 3,%ld %ld %ld\n",e,d,c);
else if (d!=0) printf("there are 2, %ld %ld\n",e,d);
else if (e!=0) printf(" there are 1,%ld\n",e);
getch();
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
wodeshangdime
2009-03-29 · TA获得超过143个赞
知道答主
回答量:121
采纳率:0%
帮助的人:0
展开全部
#include <stdio.h>
main()
{
int n,a[4],count=0,i=0,j,t;//声明变量
printf("input:");
scanf("%d",&n);//输入这个数
do//这个循环作用为分界各位放进数组当中 并且计算出这个数的位置
{
a[i]=n%10;
i++;
count++;
}while(n/=10);
printf("这个数为%d位数.\n",count);//输出这个数的组成
printf("这个数由\"");
for(i=count-1;i>=0;i--)
printf("%d ",a[i]);
printf("\"组成.\n");
for(i=1;i<=count;i++)//用冒泡法进行排序
for(j=0;j<count-i;j++)
if(a[j]>a[j+1])
{t=a[j];a[j]=a[j+1];a[j+1]=t;}
for(i=0;i<count;i++)//输出排序后的数组元素
printf("%d;",a[i]);
printf("\n");
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
亲圆里2516
2009-03-29 · TA获得超过191个赞
知道小有建树答主
回答量:535
采纳率:0%
帮助的人:261万
展开全部
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void sortA(int *arry, int aSize);

void main()
{
char buf[6];
int *arry;
while(1)
{
printf("pls input a number...\n");
scanf("%s", buf);
int nLen = strlen(buf);
if(nLen>5)
{
printf("the number overlong\n");
continue;
}
for(int i=0; i<nLen; i++)
{
if(buf[i]<48 || buf[i]>57)
{
printf("Not a number...\n");
break;
}
}
if(i<nLen) continue;

printf("这个数为%d位数\n这个数由数字\"", nLen);
arry = (int*)malloc(sizeof(int) * nLen);
for(i=0; i<nLen; i++)
{
arry[i] = buf[i] - 48;
printf("%d.", arry[i]);
}
printf("\"组成\n");

sortA(arry, nLen);

printf("排序后为:");
for(i=0; i<nLen; i++)
printf("%d\t", arry[i]);

printf("\n");

free(arry);

printf("input \"yes\" continue, otherwise exit...\n");
scanf("%s", buf);
if(strcmp(buf, "yes") != 0)
break;
}
}

void sortA(int *arry, int aSize)
{
int temp;
for(int i=0; i<aSize; i++)
for(int j=i+1; j<aSize; j++)
{
if(arry[i]>arry[j])
{
temp = arry[i];
arry[i] = arry[j];
arry[j] = temp;
}
}
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2009-03-29
展开全部
本人也是新手,特来献丑,希望共同探讨,我的拙作如下:
#include"stdio.h"
void main(int argc,char * argv)
{
int number;
int dig[5];
int count;
int i,j,tem1,tem2;

for(i=0;i<5;i++)
dig[i]=0;
printf("请输入一个不超过5位的数:");
scanf("%d",&number);

tem2=10000;
count=0;
for(i=0;i<5;i++){
dig[i]=number/tem2;
number=number%tem2;
tem2/=10;
}

for(i=0;i<5;i++)
if(dig[i]!=0)
break;
count=5-i;
printf("你输入的数为%d位数\n",count);
printf("这个数字由这几个数字组成:");
j=i;
for(;i<5;i++)
printf("%3d",dig[i]);
printf("\n");
tem2=j;
for(;j<5;j++){
for(i=j+1;i<5;i++){
if(dig[j]>dig[i]){
tem1=dig[j];
dig[j]=dig[i];
dig[i]=tem1;
}
}
}
printf("其大小顺序为:");
for(;tem2<5;tem2++)
printf("%2d",dig[tem2]);
printf("\n");
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
xwqiangcb
2009-03-29 · 超过27用户采纳过TA的回答
知道答主
回答量:176
采纳率:0%
帮助的人:74.3万
展开全部
看一下,写了前两个功能,好像错了
#include "stdio.h"
int fun(int b)
{int c;
c=b%10;
printf("%d\t",c);
b=b/10;
return b;
}
void main()
{
int a,b;
printf("请输入");
scanf("%d",&a);
b=a;
while(b!=0)
fun(b);
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式