C++에는 5개의 기본 산술 연산자가 있습니다. 그들은 -
- 추가(+)
- 빼기(-)
- 사업부(/)
- 곱하기(*)
- 모듈로(%)
이 연산자는 C++의 모든 산술 연산에 사용할 수 있습니다. 예를 살펴보겠습니다 -
예
#include <iostream>
using namespace std;
main() {
int a = 21;
int b = 10;
int c ;
c = a + b;
cout << "Line 1 - Value of c is :" << c << endl ;
c = a - b;
cout << "Line 2 - Value of c is :" << c << endl ;
c = a * b;
cout << "Line 3 - Value of c is :" << c << endl ;
c = a / b;
cout << "Line 4 - Value of c is :" << c << endl ;
c = a % b;
cout << "Line 5 - Value of c is :" << c << endl ;
return 0;
} 출력
이것은 출력을 제공합니다 -
Line 1 - Value of c is :31 Line 2 - Value of c is :11 Line 3 - Value of c is :210 Line 4 - Value of c is :2 Line 5 - Value of c is :1