wt is output if a=2.0,b=2.5 #include <iostream> using namespace std; int main() { int a, b; int sum; cout << "Enter a number \n"; cin >> a; cout << "Enter another number \n"; cin >> b; sum = a + b; cout << "Sum is: " << sum << endl; return 0; } | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

wt is output if a=2.0,b=2.5 #include <iostream> using namespace std; int main() { int a, b; int sum; cout << "Enter a number \n"; cin >> a; cout << "Enter another number \n"; cin >> b; sum = a + b; cout << "Sum is: " << sum << endl; return 0; }

10th Jul 2016, 7:37 AM
Manikumar Gouni
Manikumar Gouni - avatar
21 Answers
+ 4
answer would be 4 it is bcoz since u hav taken a and b as int.. so the compiler takes in value of b as 2 rather than 2.5... and also value of a as just 2 instead of 2.0.. so in short u have declared int variables so it would not accept float types. so answer is 4..😊
10th Jul 2016, 5:17 PM
Shrinidhi Sanket
Shrinidhi Sanket - avatar
+ 3
Declare it as float for accuracy
10th Jul 2016, 7:54 AM
sourav h
sourav h - avatar
+ 2
4 since uhave declared it as int
10th Jul 2016, 8:12 AM
simy
+ 2
4 as in variable declaration it has been declared as int
10th Jul 2016, 9:09 AM
Shankar Abrol
Shankar Abrol - avatar
+ 2
4 as the declared data type are of integer type
10th Jul 2016, 11:20 AM
utkarsh
+ 2
The answer is 4 since u have declared it as an integer, if it was float then it wud have been 4.5
11th Jul 2016, 9:49 AM
A.S Imthiyaz
A.S Imthiyaz - avatar
+ 2
Integars are whole numbers. Any and all numbers to the right of a decimal are dropped for the Integar data type. Declare it as a float to allow for decimals.
16th Jul 2016, 4:22 AM
David
David - avatar
+ 1
4
10th Jul 2016, 8:11 AM
®billa
®billa - avatar
+ 1
4
10th Jul 2016, 9:49 AM
Praneethkumar Sajalu
Praneethkumar Sajalu - avatar
+ 1
4
10th Jul 2016, 9:53 AM
piyush
+ 1
ans is:4, as variables have data type as int in declaration
10th Jul 2016, 3:08 PM
Kiran Borade
Kiran Borade - avatar
+ 1
4 because you declared sum as integer. if you want the real, mathematical result, change all variables type as double
10th Jul 2016, 4:02 PM
Cristi
Cristi - avatar
+ 1
answer is 4 because you have declared b as int so it takes only integer value if you have given double or float for b it will display the answer as 4.5
10th Jul 2016, 6:03 PM
kasi gunda
kasi gunda - avatar
+ 1
4 is ur answer, and if u use 'float' instead of 'int' then ur ans will be 4.5.
11th Jul 2016, 4:20 AM
sourabh jawalkar
sourabh jawalkar - avatar
+ 1
the output will be "Sum is 4
12th Jul 2016, 8:19 PM
Peter Lawal
Peter Lawal - avatar
+ 1
to want accurate answer use float instead of int so the compiler will consider value of b as 2.5 otherwise in int it will consider 2.
15th Jul 2016, 3:15 PM
Jay Mistry
Jay Mistry - avatar
+ 1
4
16th Jul 2016, 5:07 PM
krishna desai
+ 1
the output would be 4 as the compiler takes 2.0 as 2 in case of integer type variable declaration and 2.5 would be taken as 2 because u know int type variable. so simply the compiler would sum like 2+2 and ur answer would be 4
5th Aug 2016, 5:42 PM
pranjay
pranjay - avatar
+ 1
Sum is 4.5
5th Aug 2016, 5:59 PM
Parth Umraliya
Parth Umraliya - avatar
+ 1
4
6th Aug 2016, 2:22 AM
krishna desai