Computer Science, asked by khushiyadav4697, 9 months ago

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 szwmkhabela
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