-
help
can some one help me i have this code but i need to find the max and min number i dont know how.
Code:
/* LAB 2
* Cery */
#include <stdio.h>
int main(void)
{
float seq, sum = 0, mean;
int status, num = 0;
printf("Enter number \n");
scanf("%f", &seq);
while (status)
{
num++;
sum = sum + seq;
printf("Enter number(press q to finnish) \n");
status = scanf("%f", &seq);
mean = sum / num;
}
printf("The number you entered are: %d times\n",num);
printf("The sum is: %f\n", sum);
printf("The Max of the number: %d\n",seq);
printf("the mean value is: %f\n", mean);
return 0;
}
-
-
After the user inputs the first number, (and only for the first number), set min and max variables to that number.
Then, after each number is input, compare the new number, with the min and the max values.
if(newNumber < min) min = newNumber
if(newNumber > max) max = newNumber
-
this is what i did but still it just print the first as min and the last as max,and after this i still have to find the mean square deviation (i dont even know what that mean) but thanks man appreciated what you've done.
Code:
/* LAB 2
* Cery */
#include <stdio.h>
int main(void)
{
float seq, sum = 0, mean, min, max;
int status, num = 0;
printf("Enter number \n");
scanf("%f", &seq);
min = max = seq;
while (status)
{
num++;
sum += seq;
printf("Enter number(press q to finnish) \n");
status = scanf("%f", &seq);
mean = sum / num;
}
if(seq < min) min = seq;
printf("The Min of the number: %f\n",min);
if(seq > max) max = seq;
printf("The Max of the number: %f\n",max);
printf("The number you entered are: %d times\n",num);
printf("The sum is: %f\n", sum);
printf("the mean value is: %f\n", mean);
return 0;
}
-
no worries i got it now thanks Adak, now to find this mean square deviation.
-
Thanks Adak but i will stick to my own code i figure out for the min max and, got the mean square deviation but i dont know is he result it print is correct,cuz every time i calculate with calculator i have diverent value,
Code:
/* LAB 2
* Cery */
/***********************The Code****************************/
#include <stdio.h>
#include <math.h>
int main(void)
{
float seq, sum = 0, mean, min, max;
double squ;
int status, num = 0;
printf("Enter number \n");
scanf("%f", &seq);
min = max = seq ;
while (status)
{
num++;
sum += seq;
if(seq < min) min = seq;
if(seq > max) max = seq;
printf("Enter number(c to calculate) \n");
status = scanf("%f", &seq);
mean = sum / num;
squ = sqrt((pow(sum,2)-num*pow(mean,2))/(num-1));
}
printf("You Entered: %d times\n",num);
printf("The Sum is: %f\n", sum);
printf("The Max of the number: %.2f\n",max);
printf("The Min of the number: %.2f\n",min);
printf("The Mean is: %f\n", mean);
printf("The Mean Square Deviation is: %f\n", squ);
return 0;
}
-
Hallo, i have a question how do we use atan2 function ?
-
How do you want to use it?
You need to:
and link to the math library. If you are using gcc, that means compiling with the -lm switch:
gcc mycode.c -lm
-
i want to put a formula
tanϕ=y/x and x=r cosϕ and y=r sinϕ
atan2() than what do i put inside?
i'm using MSVC++ 6.0
-
Trig is not my strong point.
You can look here for a description of atan2():
The Open Group Base Specifications Issue 7
altho you will have to click on "Alphabetic Index", then A (atan2 is about half way down) since I cannot link directly to that page. There is also an example of code using atan2 on there.
MS libraries are probably not POSIX compliant, but POSIX is C compliant so their documentation is fine to use and usually well written.
-
-
any one know how to use atan2 function?
-
Has it occurred to you, over the past nearly 24 hours, to use...GOOGLE?
-
Possibly this is more of a math question than a C specific question?
If an actual working example (which you have already seen) does not make sense to you, there is really nothing more to explain as far as the command goes.
Or else, you could post
1) how you have tried to use it,
2) what that did
3) explain what you actually wanted to happen.
-