C program compile but not doing the calculations
Hello all,
I wrote a C program and I compile with Miracle C - a C compiler software, the program was compiled successfully but does not do any calculations under it. All the calculations I put there was not done, I included math.h and stdio.h, is there anything I am doing wrong??
Below is the program:
Code:
/* program to calculate the geometric and arithmetric average of a set of numbers*/
#include <stdio.h>
#include <math.h>
main()
{
float y, x, xavg, xavg1, temp=1.0, sum=0.0;
int count=1, n;
printf ("\nEnter the total items to calculate\n");
scanf ("%d", &n);
while (count<=n)
{
printf ("\nEnter x\n");
scanf ("%f", &x);
temp*=x;
sum+=x;
++count;
};
y = 1/n;
xavg= pow(temp, y);
xavg1= sum/n;
printf ("\nThe geometric average is %f\n", &xavg);
printf ("\nThe arithmetric average is %f\n", &xavg1);
}
I need help urgently!!!!!
The argument in printf statement went wrong
Remove the '&' in printf statement for the variables
Quote:
Originally Posted by abs.emailverify
Hello all,
I wrote a C program and I compile with Miracle C - a C compiler software, the program was compiled successfully but does not do any calculations under it. All the calculations I put there was not done, I included math.h and stdio.h, is there anything I am doing wrong??
Below is the program:
Code:
/* program to calculate the geometric and arithmetric average of a set of numbers*/
#include <stdio.h>
#include <math.h>
main()
{
float y, x, xavg, xavg1, temp=1.0, sum=0.0;
int count=1, n;
printf ("\nEnter the total items to calculate\n");
scanf ("%d", &n);
while (count<=n)
{
printf ("\nEnter x\n");
scanf ("%f", &x);
temp*=x;
sum+=x;
++count;
};
y = 1/n;
xavg= pow(temp, y);
xavg1= sum/n;
printf ("\nThe geometric average is %f\n", &xavg);
printf ("\nThe arithmetric average is %f\n", &xavg1);
}
I need help urgently!!!!!
The function you used goes wrong
FYI
#include <math.h>
double pow(double x, double y);
float powf(float x, float y);
long double powl(long double x, long double y);
So try to change code as per your requirement.
Quote:
Originally Posted by abs.emailverify
I did that but I am not getting the correct answer, I use my calculator and I got a different answer. No matter the values I entered I got 1.00 as answer or maybe I am doing something wrong?