在此谢谢啦!
给一个不多于5位的正整数,要求:
1>:求出它是几位数;
2>:分别打印出每一位数字;
3>:按逆序打印出各位数字,例如原数为321,应输出123;
别说什么基础不好,这题需要基础吗?只要听一点课就会做了
下次别起这样的名字,我先改了
-----------feng1256
#include <stdio.h>
#define N 10
static int Decompose(int a[], long num);
int main(void)
{
long num;
int a[N], i, len;
printf("Enter long num: ");
scanf("%ld", &num);
len = Decompose(a, num);
printf("len = %d\n", len);
for (i = len - 1; i >= 0; i--) /* 正序 */
{
printf("%d", a[i]);
}
printf("\n");
for (i = 0; i <= len - 1; i++) /* 逆序 */
{
printf("%d", a[i]);
}
printf("\n");
return 0;
}
static int Decompose(int a[], long num)
{
int len = 0;
while (num != 0)
{
a[len++] = num % 10;
num /= 10;
}
return len;
}
#include "string.h"
int main(int argc, char* argv[])
{
int intScore, intTmp;
char chararScore[10];
printf("\nplease input an number:\n");
scanf("%d",&intScore);
sprintf(chararScore, "%d", intScore);
printf("number of digit is %d\n", strlen(chararScore));
printf("%s\n", chararScore);
intTmp = strlen(chararScore) - 1;
while (intTmp >= 0)
printf("%c", chararScore[intTmp--]);
printf("\n");
return 0;
}