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

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

谢谢高手帮忙呀!!!!

#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);