C语言取出一个三位整数的各个位,并输出

#include<stdio.h>
main()
{
int x=123; charc1,c2,c3;
……
printf(“%d,%d,%d\n”,c3,c2,c1);
}
省略号的地方怎么补

程序如下:

#include "stdio.h"
int main(void)
{
int num,g,s,b;
printf ("请输入一个三位数num=");
scanf("%d",&num);
g=num%10;
s=num/10%10;
b=num/100;
printf("这个三位数的个位g=%d,十位s=%d,百位b=%d\n",g,s,b);
return 0;
}

程序运行结果:

如输入123;

请输入一个三位数num=123

这个三位数的个位g=3,十位s=2,百位b=1

Press any key to continue

温馨提示:内容为网友见解,仅供参考
第1个回答  2015-04-02
#include<stdio.h>
int main()
{
    int x = 123;
    int c1, c2, c3;
    c1 = x / 100;
    c2 = x / 10 % 10;
    c3 = x % 10;
    printf("%d %d %d", c1, c2, c3);
    return 0;
}

差不多这样就可以实现。。

本回答被网友采纳
第2个回答  2015-04-02
c3=x/100;
c2=x/10%10;
c1=x%10;

本回答被网友采纳
第3个回答  2018-02-03
#include <stdio.h>
main()
{
int a,b,c,rel,t;
printf("输入一个三位数:");
scanf("%d",&rel);
a=rel/100;
c=rel%10;
b=rel/10%10;
t=a;
a=c;
c=t;
printf("%d%d%d",a,b,c);
}
相似回答