English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i need the operator used for this and a simple exsample

ps:i am not talking about mod %

2006-10-09 01:40:04 · 3 answers · asked by Rami 5 in Computers & Internet Programming & Design

3 answers

In C++ the "/" operator can be used for floating point division or for real division! it depends on what type of variable you use.
To perform an integer division: simply use "/" with two int variables or, if your variables are floating point, simply cast to integer with the operator "(int)".

Similarly you can force a floating point division by using the cast to float operator "(float)".

Example:
=======
#include
using namespace std;


void main()
{
float float1=3.333;
float float2=1.5;

int int1=26;
int int2=5;

//output the reversed text
cout << "Floating point division" << endl;
cout << float1 << " / " << float2 << " = " << float1/float2 << endl;
cout << int1 << " / " << int2 << " = " << (float)int1/int2 << endl;

cout << endl << "Integer division" << endl;
cout << float1 << " / " << float2 << " = " << (int)float1/float2 << endl;
cout << int1 << " / " << int2 << " = " << int1/int2 << endl;

}

Output:
=====
Floating point division
3.333 / 1.5 = 2.222
26 / 5 = 5.2

Integer division
3.333 / 1.5 = 2
26 / 5 = 5

2006-10-09 09:20:40 · answer #1 · answered by cd4017 4 · 2 0

it somewhat is right, and then to maintain going, you're able to do 1234 % 10 to get in basic terms the 4. The integer branch does not around, it in basic terms cuts off the relax bits. in case you decide directly to around, first upload .5, THEN truncate or solid to int. it somewhat is what the processor itself does with idiv assembly operation. The idiv education divides the contents of the sixty 4 bit integer EDX:EAX (built by utilising viewing EDX because of the fact the main important 4 bytes and EAX because of the fact the least important 4 bytes) by utilising the specified operand cost. The quotient results of the branch is saved into EAX, collectively as something is placed in EDX.

2016-12-16 04:39:22 · answer #2 · answered by ? 3 · 0 0

Do a normal division and truncate.

Rawlyn.

2006-10-09 01:52:14 · answer #3 · answered by Anonymous · 0 1

fedest.com, questions and answers