1. 程式人生 > >C 拆分各個位上的數字,並抽取任意位上數計算問題

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

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