Write a menu driven program to print the sum of the following series-[10]i)S=1 + (1/3) + (1/5) + ...... + (1/19)ii)S = a2+ a2/ 2 + a2/ 3 + ...... + a2/ 10
Answers
Answered by
0
Answer:
// C++ program to find the sum of
// the given series
#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;
// Function to return the
// sum of the series
float getSum(int a, int n)
{
// variable to store the answer
float sum = 0;
for (int i = 1; i <= n; ++i)
{
// Math.pow(x, y) returns x^y
sum += (i / pow(a, i));
}
return sum;
}
// Driver code
int main()
{
int a = 3, n = 3;
// Print the sum of the series
cout << (getSum(a, n));
return 0;
}
// This code is contributed
Similar questions