+ 4

[SOLVED] Why does my program output "inf"??

The program is supposed to print an approximation of pi. Why am I getting inf? https://code.sololearn.com/c2vgob6m3Vrf/?ref=app https://www.sololearn.com/post/748624/?ref=app

9th Nov 2020, 11:09 PM
Davide
Davide - avatar
3 Respostas
+ 3
in your first if statement, you divide 4 by 0. That seems to be a problem
9th Nov 2020, 11:16 PM
Slick
Slick - avatar
+ 4
Slick Benjamin Jürgens you are right, and I didn't even needed to start the loop from 1. Now I know that I need to check for this kind of stuff when I get "inf" Thank you so much 🤗
9th Nov 2020, 11:21 PM
Davide
Davide - avatar
+ 2
In the first iteration of the loop i=1, so i*i*i-i=1-1=0 and 4.0/0=inf
9th Nov 2020, 11:18 PM
Benjamin Jürgens
Benjamin Jürgens - avatar