C 拆分各个位上的数字,并抽取任意位上数计算问题

问题:

Write a program :

Inputs one five-digit number, separates the number into its individual digits

1. Prints the digits separated from one another by three spaces each

2. Prints the addition (and subtraction) of the first threedigit numbers and the last two-digit numbers

 For example, for 42139, the program should print

C 拆分各个位上的数字,并抽取任意位上数计算问题

#include<stdio.h>
#include<stdlib.h>

int n;
int a, b;
int main(void) {
	printf("Enter a five-digit number:");
	scanf_s("%d", &n);
	printf("\n");
	printf("%d   ", n / 10000);
	printf("%d   ", n / 1000 % 10);
	printf("%d   ", n / 100 % 10);
	printf("%d   ", n / 10 % 10);
	printf("%d\n", n % 10);

	printf("\n");
	//the first digit-numbers
	a = n / 100;
	b = n % 100;
	printf("Result of addition:%d\n", a + b);
	printf("Result of addition:%d\n", a - b);

	system("pause");
	return 0;
}

 

C 拆分各个位上的数字,并抽取任意位上数计算问题