1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【C++】基礎を学ぶ③~整数同士の四則演算~

Last updated at Posted at 2022-07-07

四則演算に利用する算術演算子

演算子 概要
+ 足し算
- 引き算
* 掛け算
/ 割り算

※整数同士の割り算で割り切れない場合、切り捨てされる

整数同士の四則演算を行うプログラム

#include <iostream>

using namespace std;

int main(){
  cout << 10 + 2 << endl;
  cout << 10 - 2 << endl;
  cout << 10 * 2 << endl;
  cout << 10 / 2 << endl;
  cout << 10 / 3 << endl;
  return 0;
}
12
8
20
5
3

剰余 (余り)を計算する

剰余を計算する場合、%を使う

剰余を計算するプログラム

#include <iostream>

using namespace std;

int main(){
  cout << 10 % 2 << endl;
  cout << 10 % 3 << endl;
  return 0;
}
0
1

次の記事

【C++】基礎を学ぶ④~変数の宣言と値の代入、変数の型~

1
0
0

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?