Computer Science, asked by clara88, 11 months ago

Write a c++ program for arithmetic operations

Answers

Answered by patilcourt
2

Answer:Home > Articles > Programming > C/C++

C++ Primer: Dealing with Data

By Stephen Prata

Dec 30, 2004

Contents

Simple Variables

The const Qualifier

Floating-Point Numbers

C++ Arithmetic Operators

Summary

Review Questions

Programming Exercises

This chapter is from the book 

This chapter is from the book

C++ Primer Plus, 5th EditionC++ Primer Plus, 5th Edition

Learn More Buy

C++ Arithmetic Operators

Perhaps you have warm memories of doing arithmetic drills in grade school. You can give that same pleasure to your computer. C++ uses operators to do arithmetic. It provides operators for five basic arithmetic calculations: addition, subtraction, multiplication, division, and taking the modulus. Each of these operators uses two values (called operands) to calculate a final answer. Together, the operator and its operands constitute an expression. For example, consider the following statement:

int wheels = 4 + 2;

The values 4 and 2 are operands, the + symbol is the addition operator, and 4 + 2 is an expression whose value is 6.

Here are C++'s five basic arithmetic operators:

The + operator adds its operands. For example, 4 + 20 evaluates to 24.

The - operator subtracts the second operand from the first. For example, 12 - 3 evaluates to 9.

The * operator multiplies its operands. For example, 28 * 4 evaluates to 112.

The / operator divides its first operand by the second. For example, 1000 / 5 evaluates to 200. If both operands are integers, the result is the integer portion of the quotient. For example, 17 / 3 is 5, with the fractional part discarded.

The % operator finds the modulus of its first operand with respect to the second. That is, it produces the remainder of dividing the first by the second. For example, 19 % 6 is 1 because 6 goes into 19 three times, with a remainder of 1. Both operands must be integer types; using the % operator with floating-point values causes a compile-time error. If one of the operands is negative, the sign of the result depends on the implementation.

Of course, you can use variables as well as constants for operands. Listing 3.10 does just that. Because the % operator works only with integers, we'll leave it for a later example.

Listing 3.10 arith.cpp

// arith.cpp -- some C++ arithmetic

#include <iostream>

int main()

{

using namespace std;

float hats, heads;

}

Explanation:

Hope this helps u plz mark me as the brainliest

Similar questions