- 5
Who know C++
15 ответов
+ 2
Please describe the problem.
+ 2
Jo'shqinbek Bekniyozov Ur while loop should be like this:-
while(a<=b)
{sum+=(1/a);
a++;
}
+ 2
You can learn from here https://www.cplusplus.com , it really helped me understand! you should practice when you learn something!
+ 1
Why there is a++ included twice in the loop?
Why are you using sum = sum + 1 (incrementing sum by 1) while you were supposed to increment sum by a fraction?
+ 1
You were supposed to increment sum by a fraction, not by sum itself.
+ 1
but its still better, currently all the problems are located on this statement:
sum += sum;
+ 1
With fraction I mean't 1/1, 1/2, ... 1/n in the problem description.
I can give hint that variable a represents n in the list.
(a = 1, 2, ... b)
+ 1
If this is a role call, I guess I'll say "Here"
0
Using while loop to calculate S=1/1+1/2+.....+1/n
0
#include<iostream>
using namespace std;
int main()
{
int a=1, b;
double sum = 0;
cout << "enter the number = ";
cin >> b;
while ( a <= b, a++)
{
sum = sum+ 1;
a++;
}
cout << "sum is " << sum << endl;
system("pause");
return 0;
}
It is not calculate sum
Only input valur
0
#include<iostream>
using namespace std;
int main()
{
int a=1, b;
double sum = 0;
cout << "enter the number = ";
cin >> b;
while ( a <= b )
{
sum += sum;
a++;
}
cout << "sum is " << sum << endl;
system("pause");
return 0;
}
0
Also the same problem
0
Sum is 0😕😕
- 1
Thank you
- 2
Please help me