1. 程式人生 > >C語言開發筆記(四)獲取整數的個十百千位

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;
}