0

How to obtain sum of reciprocal of integers up to an input value?

including the input value

8th Sep 2016, 4:40 PM
Lavnish
Lavnish - avatar
2 odpowiedzi
+ 2
#include<iostream> using namespace std; int main() { float sum=0; int no,a[100]; cout<<"enter no of inputs"; cin>>no; for(int i=0;i<no;i++) {cin>>a[i]; sum+=1/a[i];} cout<<sum; return 0; }
8th Sep 2016, 5:34 PM
Shaurya Agnihotri
+ 2
http://code.sololearn.com/cVqVoEaEmcrK #include <iostream> using namespace std; double inverseSerieSum(unsigned int n) { unsigned int i; double sum; sum = 0; for (i = 1; i <= n; i++) { sum += 1.0/i; } return sum; } int main() { unsigned int n; cin >> n; cout << inverseSerieSum(n); return 0; }
8th Sep 2016, 8:54 PM
Zen
Zen - avatar