
Воеводский
5 год назад
для заданного натурального n и действительного x подсчитать:S=1+1/sqrt(2)+1/sgrt(3)+...+1/sgrt(n)вот код программы, в чем ошибка?#include #include using namespace std;int main() {int n;float s=0,b=0;cout<<"n="; cin>>n;for (int i=1; i<=n; i++){b=(1/sqrt(n)); s+=b;}cout <<"s="<return 0;}
ОТВЕТЫ

Stancho
Oct 24, 2020
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
float s = 1,b = 0;
cout << "n=";
cin >> n;
for (int i=2; i<=n; i++){
b=(1/sqrt(i));
s += b;
}
cout <<"s="<< s << endl;
return 0;
}
#include <cmath>
using namespace std;
int main() {
int n;
float s = 1,b = 0;
cout << "n=";
cin >> n;
for (int i=2; i<=n; i++){
b=(1/sqrt(i));
s += b;
}
cout <<"s="<< s << endl;
return 0;
}
688
Смежные вопросы: