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 ...

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. Use bubble sort

3. whats tat?
i am a rookie...

4. 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. 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. erm.
how can i keep tracking the smallest value i ever entered?
and show in after exited

7. Originally Posted by imbax
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.