我自己编了一下...可以将数字的各位分离出来....并求出最大和最小值..不过这个小程序只能处理INT型数据....如果想处理LONG等..自己再看看吧...
#include <stdio.h>
#include <stdlib.h> //使用itoa,将一整型数转化成字符串
#include <string.h>
#include <math.h>
int main()
{
const int ARRAY_SIZE = 20;
int value,length,max,min;
char buffer[ARRAY_SIZE];
int num[ARRAY_SIZE];
printf("Please enter one number:");
scanf("%d",&value);
length = strlen(itoa(value,buffer,10));
for(int i=length-1; i>=0; i--)
{
num[i] = value / (int)pow(10,i);
value = value % (int)pow(10,i);
printf("%d\t",num[i]);
}
printf("\n");
max = num[0];
min = num[0];
for(i=length-1; i>0; i--)
{
if(max < num[i])
max = num[i];
if(min > num[i])
min = num[i];
}
printf("THe min number is: %d\nThe max number is: %d\n",min,max);
return 0;
}
#include <stdio.h>
#include <stdlib.h> //使用itoa,将一整型数转化成字符串
#include <string.h>
#include <math.h>
int main()
{
const int ARRAY_SIZE = 20;
int value,length,max,min;
char buffer[ARRAY_SIZE];
int num[ARRAY_SIZE];
printf("Please enter one number:");
scanf("%d",&value);
length = strlen(itoa(value,buffer,10));
for(int i=length-1; i>=0; i--)
{
num[i] = value / (int)pow(10,i);
value = value % (int)pow(10,i);
printf("%d\t",num[i]);
}
printf("\n");
max = num[0];
min = num[0];
for(i=length-1; i>0; i--)
{
if(max < num[i])
max = num[i];
if(min > num[i])
min = num[i];
}
printf("THe min number is: %d\nThe max number is: %d\n",min,max);
return 0;
}