0

Please help me to find sum 1+1/2^2+1/3^3

in c

30th Jun 2018, 4:02 PM
Dipu Ojha
Dipu Ojha - avatar
4 Answers
+ 2
when for example you say "1/2^2" do you mean "(1/2)^2" or "1/(2^2)"? cause mathematically those two are very different
30th Jun 2018, 4:08 PM
hinanawi
hinanawi - avatar
30th Jun 2018, 4:34 PM
hinanawi
hinanawi - avatar
0
I mean(1/2)^2sorry for inconvenience
30th Jun 2018, 4:23 PM
Dipu Ojha
Dipu Ojha - avatar
0
in c to raise a number to power you should use a pow function from math.h library (or cmath if it's c++). So you should #include <math.h> and then float sum = 1.0+pow(1.0/2.0, 2)+pow(1.0/3.0, 2) or, instead of using pow you can actually do float sum = 1.0+((1.0/2.0)*(1.0/2.0))+((1.0/3.0)*(1.0/3.0)*(1.0/3.0)) it will actually be calculated faster, then the variant with pow
30th Jun 2018, 4:34 PM
Š”Š¼ŠøтрŠ¾ Š†Š²Š°Š½Š¾Š²
Š”Š¼ŠøтрŠ¾ Š†Š²Š°Š½Š¾Š² - avatar