C语言中整数123取十位数表达式
1个回答
关注
展开全部
咨询记录 · 回答于2024-01-19
C语言中整数123取十位数表达式
#include
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\n", unitPlace);
printf("十位:%d\n", tenPlace);
printf("百位:%d\n", hundredPlace);
printf("千位:%d\n", thousandPlace);
getchar();
return 0;