0

C++ program to read (X) and then disting uish either X is an odd or even using (double)

27th Oct 2022, 4:26 PM
Younis Ahmad
Younis Ahmad - avatar
4 ответов
+ 1
To calculate division remainder for floating point values, we can use fmod() from <cmath> NOTE: Since fmod() returns a floating point value, you will need to cast the returned value into integer type before using the value in making decision, the fraction may bother you if you didn't. http://www.cplusplus.com/reference/cmath/fmod/
28th Oct 2022, 4:08 AM
Ipang
+ 1
int x; std::cin >> x; if(x%2==0) { std::cout <<´´even´´; } else { std::cout <<´´odd´´; }
29th Oct 2022, 2:06 PM
Sceptre7
Sceptre7 - avatar
0
Double num; Cin>>num; if(num%2==0) { cout<<´´even´´; } else { cout<<´´odd´´; }
27th Oct 2022, 6:15 PM
Younis Ahmad
Younis Ahmad - avatar
0
Error occurs because I used double How I can solved?
27th Oct 2022, 6:16 PM
Younis Ahmad
Younis Ahmad - avatar