0
Please help me to find sum 1+1/2^2+1/3^3
in c
4 Respuestas
+ 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
+ 1
in that case here you go
https://code.sololearn.com/c150fTdhzhb5/?ref=app
0
I mean(1/2)^2sorry for inconvenience
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