![]() |
| | #1 |
| Registered User Join Date: Nov 2006
Posts: 13
| 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);
}
|
| abs.emailverify is offline | |
| | #2 | |
| Registered User Join Date: Sep 2001
Posts: 9
| The argument in printf statement went wrong Remove the '&' in printf statement for the variables Quote:
| |
| abc123 is offline | |
| | #3 |
| Registered User Join Date: Nov 2006
Posts: 13
| Thank you so much, it works. But i want to calculate x^y(x raise to power y) and dont how to write the statement in C, anyone here to help? |
| abs.emailverify is offline | |
| | #4 | |
| Registered User Join Date: Jan 2002 Location: Northern Virginia/Washington DC Metropolitan Area
Posts: 2,870
| Quote:
Code: xavg= pow(temp, y);
__________________ On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. --Charles Babbage, 1792-1871 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 | |
| hk_mp5kpdw is offline | |
| | #5 | |
| Registered User Join Date: Nov 2006
Posts: 13
| Quote:
| |
| abs.emailverify is offline | |
| | #6 | |
| Registered User Join Date: Sep 2001
Posts: 9
| 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:
| |
| abc123 is offline | |
| | #7 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,706
| > and I compile with Miracle C - a C compiler software Well there's your problem, this is a toy, not a C compiler. Trust me, it won't take long before you realise that it's a PoS. Just do yourself a big favour and get dev-C++. |
| Salem is offline | |
| | #8 |
| Registered User Join Date: Jan 2002 Location: Northern Virginia/Washington DC Metropolitan Area
Posts: 2,870
| Code: float y, x, xavg, xavg1, temp=1.0, sum=0.0; int count=1, n; ... y = 1/n; Code: y = 1.0 / n;
__________________ On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. --Charles Babbage, 1792-1871 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 |
| hk_mp5kpdw is offline | |
| | #9 |
| Registered User Join Date: Nov 2006
Posts: 13
| Thank you a lot. I have done it and is working. I so much appreciate your effort in helping me solve this problem. |
| abs.emailverify is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Program Plan | Programmer_P | C++ Programming | 0 | 05-11-2009 01:42 AM |
| Compile Public Domain Pocket PC C Program | m1l | Projects and Job Recruitment | 2 | 07-20-2007 04:02 AM |
| Using variables in system() | Afro | C Programming | 8 | 07-03-2007 12:27 PM |
| new to C--can't get program to compile | samerune | C Programming | 12 | 04-02-2007 09:44 AM |
| how do i compile a program that deals w/classes? | Shy_girl_311 | C++ Programming | 5 | 11-11-2001 02:32 AM |