Question #53417

int i=2,j=3;
float a,b;
k=i/j*j;
l=j/i*i;
a=i/j*j;
b=j/i*i;
please sir can you provide me a answer for this question and explain me

Expert's answer

#include <stdio.h>

int main()
{
int k,l; // if k and l are integer values
int i=2,j=3;
float a,b;

// i/j*j is the same in C language as (i/j)*j
// j/i*i is the same in C language as (j/i)*i
k=i/j*j; // 2/3 = 0 (because of C language specification, int/int = int), 0*3 = 0 (it's clear)
l=j/i*i; // 3/2 = 1 (because of C language specification, int/int = int), 1*2 = 2 (it's clear)
a=i/j*j; // 2/3 = 0 (because of C language specification, int/int = int), 0*3 = 0 (it's clear), a-floating number => a=0.000000
b=j/i*i; // 3/2 = 1 (because of C language specification, int/int = int), 1*2 = 2 (it's clear), b-floating number => b=2.000000

printf("%d %d %f %f", k, l, a, b); // output is "0 2 0.000000 2.000000"
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS