LoginSignup
0
1

More than 1 year has passed since last update.

C言語で百の位までの位ごとの足し算をする方法

Last updated at Posted at 2023-02-05

目的

・何も検索しないで解けるようになりたい。
AtCoderの問題分けてみた

注意

Atcoderのabc187_A - Large Digitsのネタバレあり。

解法

・四則演算 と 条件分岐を使う。
(他にもあると思うけど気が向いたら探す)

ACしたコード

#include <stdio.h>
int	main(void)
{
	int	a;
	int	b;

	scanf("%d%d",&a,&b);
	// printf("%d %d\n",a,b);

	// printf("%d\n",a / 100);			//100の位
	// printf("%d\n",(a / 10) % 10);	//10の位
	// printf("%d\n",a % 10);			//1の位

	int suma = 0;
	int sumb = 0;
	suma = a / 100 + (a / 10) % 10 + a % 10;
	sumb = b / 100 + (b / 10) % 10 + b % 10;

	if(suma >= sumb){
		printf("%d\n", suma);
	} else {
		printf("%d\n", sumb);
	}

	return (0);
}

参考にした記事まとめ

位を出力する方法

0
1
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1