define the function

Asked

Viewed 40 times

0

I am doing a language exercise c and wanted to know if anyone can help me understand how I do this function without adding library inserir a descrição da imagem aqui

i have no idea how to write it in the program,my doubt is how I raise exponents squared in these types of exercises, my primary idea, is that each sequence is multiplying by odd numbers, EX: 1/3+ 1/61/61/6, the 1 third has 1, 1 sixth has 3 , 1 ninth has 5


int main(){
  float p=1;
  int n,r,denominador=1;
//entrada de dados
  printf("escreva o números de termos a serem somados= \n");
  scanf("%d",&n);
//função
  for(int i=1;i<n;i++){
    denominador*=3;
    p= p + i/denominador;
  }
}
  • 1

    Search about the function pow of the C language.

  • a I forgot to specify q he asks without adding library,

2 answers

2

From basic mathematics, we remember that to invert the signal of an exponent, we can invert the fraction of the base. That is, x (-2) is the same as (1/x) 2, being the signal of potentiation.

So we can rewrite its expression so that:

inserir a descrição da imagem aqui

Or else...

inserir a descrição da imagem aqui

Which, mathematically, could be rewritten as:

inserir a descrição da imagem aqui

If we define a function for the sum term, f(i):

inserir a descrição da imagem aqui

We can say that:

inserir a descrição da imagem aqui

So, to rewrite in C, we just need to go through a loop of repetition from 1 to n, accumulating the value of f(i).

for (i = 1; i <= n; i++) {
  fdp += f(i);
}

Remaining only to implement f(i) in C:

float f(int i) {
  float numerator = 3*i;
  float denominator = 1;

  while (i > 0) {
    denominator *= (3*i)*(3*i);
  }

  return numerator / denominator;
}

I imagine with this you can follow up on the solution.

-1

Try something like:

float soma=0;
int pot=1;
for(i=1; i<=n; i++) {
    pot *= 3 * 3;
    soma += (i*3) * (1/pot);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.