C语言怎样提取一个数的十位个位百位千位
1 设一个数为n,则在C语言中其个位、十位、百位、千位依次这样计算:n/1%10,n/10%10,n/100%10,n/1000%10
2 示例
#include<stdio.h> int main(){ int n = 123456; int unitPlace = n / 1 % 10; int tenPlace = n / 10 % 10; int hundredPlace = n / 100 % 10; int thousandPlace = n / 1000 % 10; printf("个位:%d 十位:%d 百位:%d 千位:%d ", unitPlace, tenPlace, hundredPlace, thousandPlace); getchar(); return 0; }
运行结果:
个位:6
十位:5
百位:4
千位:3
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。