0

Can not troubleshoot what the problem is

Here is my code for calculating sum of first 100 odd numbers, #include<iostream> #include<cmath> using namespace std; int main() { int i(1),a(0),s(1); cin>>a>>s; while(i<=100) { a+=s; s+=2; i++; } cout<<"The sum is "<<a<<endl; return 0; } This C++ code doesnt given any output and i cant spot the mistake.Any help would be appreciated.

29th Dec 2020, 12:52 PM
Dex
Dex - avatar
2 Réponses
+ 1
replace the while condition with while(i<=100)
29th Dec 2020, 12:56 PM
John Robotane
John Robotane - avatar
0
thank u sir have a good day.Now its working
29th Dec 2020, 12:57 PM
Dex
Dex - avatar