Please help, how to find the smallest value i ever enter??

This is a discussion on Please help, how to find the smallest value i ever enter?? within the C Programming forums, part of the General Programming Boards category; please provide me the code, by typing 3 number, it will arrange the number from smallest to largest. and it ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    8

    Please help, how to find the smallest value i ever enter??

    please provide me the code,
    by typing 3 number, it will arrange the number from smallest to largest.
    and it will exit the loop when 3 of the number enter -1 -1 -1.
    after exit, it will show the smallest value i ever entered.

  2. #2
    Registered User
    Join Date
    Feb 2010
    Posts
    84
    Use bubble sort

  3. #3
    Registered User
    Join Date
    Sep 2010
    Posts
    8
    whats tat?
    i am a rookie...

  4. #4
    a guy with long hair Xupicor's Avatar
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    103
    It's a sorting algorithm. Simple google query would give you that information, and plenty of examples in various languages.Bubble sort - Wikipedia, the free encyclopedia

  5. #5
    Registered User
    Join Date
    Sep 2010
    Posts
    8
    Code:
    #include<stdio.h>
    
    void main(){
    
    	int x,y,z,v;
    	do{
    		
    
    		printf("1st Number:\n");
    		scanf("%d",&x);
    		printf("2nd Number:\n");
    		scanf("%d",&y);
    		printf("3rd Number:\n");
    		scanf("%d",&z);
    
    		if(x > y){
    			if(x > z){
    				if(y > z){
    					printf("Largest : %d  Medium : %d Smallest : %d  \n",x,y,z);
    				}else{
    					printf("Largest : %d  Medium : %d Smallest : %d  \n",x,z,y);
    				}
    			}else{
    				printf("Largest : %d  Medium : %d Smallest : %d  \n",z,x,y);
    			}
    		}else{
    			if(y > z){
    				if(x > z){
    					printf("Largest : %d  Medium : %d Smallest : %d  \n",y,x,z);
    				}else{
    					printf("Largest : %d  Medium : %d Smallest : %d  \n",y,z,x);
    				}
    			}else{
    				if(z > x){
    					printf("Largest : %d  Medium : %d Smallest : %d  \n",z,y,x);
    				}
    			}
    		}
    		
    	}while((x != -1)&&(y != -1)&&(z != -1));
    }
    dis is my code, can u show me how to do to show the smallest value i ever enter, before exit??

  6. #6
    Registered User
    Join Date
    Sep 2010
    Posts
    8
    erm.
    how can i keep tracking the smallest value i ever entered?
    and show in after exited

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by imbax View Post
    erm.
    how can i keep tracking the smallest value i ever entered?
    and show in after exited
    If all you care about is the lowest number you've entered you should...

    1) set up an integer variable to hold this value.
    2) initialize it to some ridiculously high value such as INT_MAX
    3) use if statements to compare new entries to the current number
    4) keep the lower of the two.
    5) print it out when you exit the program.

    If you are worried about sorting the three numbers you are entering as a group

    1) Set up an array of 3 int values
    2) put the first number in the first position
    3) if the second number is higher put it in the second position
    4) if it is lower move the first number to position 2 and put the new one in position 1
    5) repeat for third number.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help With a BlackJack Program in C
    By Jp2009 in forum C Programming
    Replies: 15
    Last Post: 03-30-2009, 10:06 AM
  2. Finding the smallest value......HARD!!!
    By AssistMe in forum C Programming
    Replies: 21
    Last Post: 03-10-2005, 05:23 AM
  3. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 10:31 PM
  4. hi need help with credit limit program
    By vaio256 in forum C++ Programming
    Replies: 4
    Last Post: 03-31-2003, 11:23 PM
  5. Enistine program
    By Mac_the vamp in forum C Programming
    Replies: 2
    Last Post: 11-11-2002, 09:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21