Write a program to calculate the value of the given expression:
1/a2 + 2/b2 + 3/c2
Take the values of a, b and c as input from the console. Finally, display the result of the expression to its nearest whole number.
Answers
Answered by
3
Answer:
Explanation:
// 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
// by Sach_Code
Similar questions
Math,
4 months ago
Chemistry,
4 months ago
Science,
4 months ago
Social Sciences,
9 months ago
English,
1 year ago