Thread: help

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    15

    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;
    }
    Last edited by juiceceri; 11-21-2009 at 12:24 PM. Reason: new problem

  2. #2
    Registered User
    Join Date
    Nov 2009
    Posts
    15
    and i cant use array!!

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    15
    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;
    }

  5. #5
    Registered User
    Join Date
    Nov 2009
    Posts
    15
    no worries i got it now thanks Adak, now to find this mean square deviation.

  6. #6
    Registered User
    Join Date
    Nov 2009
    Posts
    15
    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;
    }
    Last edited by juiceceri; 11-22-2009 at 02:22 AM.

  7. #7
    Registered User
    Join Date
    Nov 2009
    Posts
    15
    Hallo, i have a question how do we use atan2 function ?

  8. #8
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    How do you want to use it?

    You need to:
    Code:
    #include <math.h>
    and link to the math library. If you are using gcc, that means compiling with the -lm switch:

    gcc mycode.c -lm
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  9. #9
    Registered User
    Join Date
    Nov 2009
    Posts
    15
    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

  10. #10
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    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.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  11. #11
    Registered User
    Join Date
    Nov 2009
    Posts
    15
    thanks MK27.

  12. #12
    Registered User
    Join Date
    Nov 2009
    Posts
    15
    any one know how to use atan2 function?

  13. #13
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Has it occurred to you, over the past nearly 24 hours, to use...GOOGLE?

  14. #14
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    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.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  15. #15
    Registered User
    Join Date
    Nov 2009
    Posts
    15
    thanks i found it
    Last edited by juiceceri; 11-23-2009 at 01:00 PM.

Popular pages Recent additions subscribe to a feed