0

Why there is 0 in output????????????😭😭😭😭😭😭

#include <iostream> using namespace std; int main() { int x; int n; cin >> x; cin >> n; double result; double resultFinal=1; if(n>0){ for(int i=0;i<=n;i++){ result = x/(n+i); resultFinal = result*resultFinal; } } cout<<resultFinal; }

10th Sep 2019, 12:32 PM
Марія Селезньова
Марія Селезньова - avatar
2 odpowiedzi
+ 4
when n >0 at the end of the loop you will get a division where x < (n+i) since it's an integer division it will return 0. 0 * resultFinal will always be 0 cast the division to return double instead.
10th Sep 2019, 1:01 PM
Bahhaⵣ
Bahhaⵣ - avatar