C语言使用if判断语句实现求整数几位数并逆序打印出各位数字 要求:给一个不多于5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字。
#include "stdio.h"
int main() {
int a,a1,a2,a3,a4,a5,a6;
scanf("%d",&a);
a1=a%10;
a2=a%100;
a3=a%1000;
a4=a%10000;
a5=a/10000;
a6=a/10;
if (a>10000&&a<99999)
{
printf("there are 5, %d %d %d %d %d",a1,a2/10,a3/100,a4/1000,a5);
}
else if (a>1000&&a<9999)
{
printf("there are 4, %d %d %d %d",a1,a2/10,a3/100,a/1000);
}
else if (a>100&&a<999)
{
printf("there are 3, %d %d %d",a1,a2/10,a/100);
}
else if (a>10&&a<99)
{
printf("there are 2, %d %d",a1,a6);
}
else
{
printf("there are 1, %d",a);
}
}
#include "stdio.h"
#include "math.h"
int main()
{
char c1='C', c2='h', c3='i', c4='n', c5='a';
c1=c1+4;
c2=c2+4;
c3=c3+4;
c4=c4+4;
c5=c5+4;
printf("%c%c%c%c%c",c1,c2,c3,c4,c5);
return 0;
}
|