C语言开发笔记(四)获取整数的个十百千位

#include <stdio.h>

int main(void)
{
	unsigned int number = 0;
	unsigned int single_digit = 0;
	unsigned int ten_digit = 0;
	unsigned int hundreds_digit = 0;
	unsigned int thousands_digit = 0;

	scanf("%d", &number);

	thousands_digit =  number / 1000;
	hundreds_digit  =  number % 1000 / 100;
	ten_digit       =  number % 1000 % 100 / 10;
	single_digit    =  number % 1000 % 100 % 10;
	
	printf("%d, %d, %d, %d\n", thousands_digit, hundreds_digit, ten_digit, single_digit);

	return 0;
}

猜你喜欢

转载自blog.csdn.net/Dr_Haven/article/details/82755762