Explain with suitable example, the following operations :

1) Integer arithmetic 2) Real Arithmetic   3) Mixed mode arithmetic.

Types of arithmetic instructions:

Arithmetic instruction is a combination of constants, variables and arithmetic operators that yields a value. In the previous session we have discussed presidency, associatively of arithmetic operators and evaluation of an arithmetic expression. Now we will address some of the issues regarding to types in arithmetic expressions. According to the type of operands arithmetic instructions are classified into

  1. Integer Mode Arithmetic Instructions
  2. Real Mode Arithmetic Instructions
  3. Mixed Mode Arithmetic Instructions

1. Integer Mode Arithmetic Instruction:

In an arithmetic expression, if every operand is of integer type then the instruction is called integer mode arithmetic instruction. It always yields an integer result

Example:

#include<stdio.h>

int main()

{

float x,y;

x=5/2;       /* yields only 2 instead of 2.5 */

y=2/5;      /* yields only 0 instead of 0.4 */

printf(“%f\n%f”,x,y);

return 0;

}

Output:

2.000000

0.000000

Example explained:

In x=5/2; both 5 and 2 are integer constants that yields an integer value 2 instead 2.5.

In y=2/5; both 2 and 5 are integer constants that yield an integer value 0 instead 0.4

2. Real Mode Arithmetic Instruction:

In an arithmetic expression, if every operand is of real type then the instruction is called real mode arithmetic instruction. It always yields a real result.

#include<stdio.h>

int main()

{

float x,y;

x=5.0/2.0;     /* yields 2.5 */

y=2.0/5.0;     /* yields 0.4 */

printf(“%f\n%f”,x,y);

return 0;

}

Output:

2.500000

0.400000

Example explained:

In x=5.0/2.0; both 5.0 and 2.0 are real constants that yields a real value 2.5

In y=2.0/5.0; both 2.0 and 5.0 are real constants that yields a real value 0.4

3. Mixed Mode Arithmetic Instruction:

In an arithmetic expression, if operands are of both integer and real types then the instruction is called mixed mode arithmetic instruction. It always yields a real value as result.

#include<stdio.h>

int main()

{

float x,y;

x=5/2.0;/* yields 2.5 */

y=2.0/5;/* yields 0.4 */

printf(“%f\n%f”,x,y);

return 0;

}

Output:

2.500000

0.400000