How to solve the expression (a/b)+(c/d) using typecasting in c
#include <iostream>using namespace std;int main() { int a, b, c, d; cout<<"Enter a and b: "; cin>>a>>b; cout<<"Enter c and d: "; cin>>c>>d; float ans = (a/b)+(c/d); cout<<"Answer(without typecast) = "<<ans<<"\n"; ans = ((float)a/b)+((float)c/d); cout<<"Answer(with typecast) = "<<ans<<"\n"; return 0;}Why the output is in 'int' type but not 'float' type?But the same program in C came with output of 'float' type.
In assignment question, i can understand typecasting of given expression but what is the meaning of real division in type casting?
33590 visits
Outline: Increment and Decrement Operators -Increment Operator --example: ++ -Postfix increment --example: a++ -Prefix increment --example: ++a -Decrement Operator --example: -- -Postfix decrement --example: a-- -Prefix decrement --example: --a -Typecasting -Errors
Increment and Decrement Operators -Increment Operator --example: ++ -Postfix increment --example: a++ -Prefix increment --example: ++a -Decrement Operator --example: -- -Postfix decrement --example: a-- -Prefix decrement --example: --a -Typecasting -Errors
Show video info
Pre-requisite