-2
Hello, I’m a beginner in the programming area and I’m doing a program that calculates some types of averages, but in the geometric average the formula uses root quarter of a.b.c.d, I thought to use the sqrt function but if I’m not mistaken it only makes square root, how can I do this account?
#include <stdio.h>
#include <math.h>
int main(void) {
  int cod;
  float nota1, nota2, nota3, nota4, media;
  printf("Insira a primeira nota: ");
    scanf("%f", ¬a1);
  getchar();
  printf("Insira a segunda nota: ");
    scanf("%f", ¬a2);
  getchar();  
  printf("Insira a terceira nota: ");
    scanf("%f", ¬a3);
  getchar();  
  printf("Insira a quarta nota: ");
    scanf("%f", ¬a4);
  getchar();    
  printf(" \n 1: Aritmetica \n 2: Harmonica \n 3: Geometrica \n 4: Quadratica \n\n Insira o codigo da media que deseja: ");
    scanf("%d", &cod);
  getchar(); 
  if (cod == 1){
    media = (nota1 + nota2 + nota3 + nota4 )/4;
      printf("Media: %.2f", media);
  }    
  if (cod == 2){
    media = (4/((1/nota1)+(1/nota2)+(1/nota3)+(1/nota4)));
      printf("Media: %.2f", media);    
  }
  if (cod == 3){
    media = 
      printf("Media: %.2f", media);    
  }
  if (cod == 4){
    media = (sqrt((pow(nota1, 2) + pow(nota2, 2) + pow(nota3, 2) + pow(nota4, 2))/4));
      printf("Media: %.2f", media);
  }
  return 0;
}
						
An alternative is to use the function
pow(x, 1.0/4.0)of <Math. h>.– anonimo
Thanks, I think it worked, I did so: if (Cod == 3){ media = Pow(Nota1 * nota2 * nota3 * nota4, 1.0/4.0); printf("Media: %.2f", media); }
– Luis Artur
The square root of the square root is the fourth root, so
sqrt(sqrt(x))would do. But as a general rule, use the above hint (root n of x is the same as x raised to 1/n)– hkotsubo