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

本文介绍了一个C语言程序,该程序接收一个五位数输入,将其拆分为各个数字并打印出来,同时计算前三位数字与后两位数字的加减运算结果。通过示例演示了如何使用位运算和算术运算实现这一功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题:

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 main(void) {
	
	int num;
	printf("Enter a five-digit number:");
	scanf_s("%d", &num);

	printf("%d   %d   %d   %d   %d\n", num / 10000, num / 1000 % 10, num / 100 % 10, num / 10 % 10, num % 10);
	printf("Result of addition:%d\n", num / 100 + num % 100);
	printf("Result of subtraction:%d\n", num / 100 - (num % 100));

	system("pause");
	return 0;
}

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值