+ 2
Why it is not giving right output ? Please help me . Thanks you for help . ☺️
8 Respuestas
+ 2
Corrected Code https://code.sololearn.com/c3A2Y4o6l9hN/?ref=app
+ 3
2n-1 is the general formula to find the nth odd number.
+ 2
Simba n is the number of terms not the last term
eg. n = 3 will be 1+3+5 = 9 (three terms)
+ 2
Thanks infinity sir . Code is exactly right . Sir if you have time may you please explain logic of i*2-1 .
+ 1
It returns 16 for input 7.(1+3+5+7)
What's your expected output?
+ 1
Yes sir but it for 7 it should be ( 1+3+5+7+9+11+13) = 49 . Means 7 terms . but it is giving different output .
+ 1
I have two things to say:
1. This is an arithmatic progression. You can use the formula directly to find the sum of an AP of n terms.
2. Since in this case, it is sum of odd natural numbers of n terms, the output will always be n^2
(ex: n = 7, output = 49
n = 8, output = 64
n = 10, output = 100)
No need to write the code in my opinion
Abhay mishra please read this
0
for(i=1;i<=terms*2;i=i+2) {