-4
#include <stdio.h>
#include <locale.h>
#include <conio.h>
#include <string.h>
#include <math.h>

int main()
{

 int array[5];
 int x;
 int max;
 int y;
 float k;

 printf("Enter capacity of array")
 scanf("%d",&y);

 for(x=0;x<y;x++)
    {
     printf("Enter the numbers:");  
     scanf("%d",&array[x]);
     max*=array[x]; 
    }

  k=pow(max,(1/y) );

  printf("%d\n",max); 
  printf(" %f",k);

 getch();
 }

Hello everyone, I want find geometric average but I always get k=1 I know it's simple code but I can't see the problem, can anyone help me?

aek8
  • 319
  • 1
  • 8
  • 22
4alerce
  • 3
  • 3

3 Answers3

1

With int y, the expression 1/y is equal to 0 in most cases...

More precisely, in all cases, except for when y is -1 or 0 or +1.

So you might want to start by changing it to 1.0/y...

goodvibration
  • 5,980
  • 4
  • 28
  • 61
  • 1
    P.S.: the variable `max` is not even initialized in your code, so I guess you've got a whole bunch of other problems there... – goodvibration Jan 26 '18 at 21:18
-1

check this out.

#include <stdio.h>
#include <math.h>
int main()
{
    double array[5];
    int max = 1, y;
    printf("Enter Capacity of Array:\n");
    scanf("%d", &y);
    for (int i = 0;i < y;i++)
    {
        printf("Enter the %d Number:\n",i+1);
        scanf("%lf", &array[i]);
        max *= array[i];
    }
    printf("Multiplication Of Array = %d\n\n", max);
    printf("Geomteric Mean = %0.2lf\n", pow(max, (1.0/y)));
    getch();
}
-1
#include <stdio.h>
#include <conio.h>
#include <math.h>

int main()
{
int x;
int max = 1;
int y;
float k;

printf("Enter capacity of array");
scanf("%d",&y);
int array[y];

for(x=0;x<y;x++)
    {
    printf("Enter the %d number:",x+1);  
    scanf("%d",&array[x]);
    max*=array[x]; 
    }

k=pow(max,(1.0/y) );

printf("%d\n",max); 
printf("%f",k);
getch();

}

Hope this will help

Akshara
  • 127
  • 1
  • 2
  • 12