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; }
2 Respuestas
+ 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.