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.
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.
Use bubble sort
whats tat?
i am a rookie...
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
If you want people to help you, try to provide Short, Self Contained, Correct (Compilable), Example, and Don't be a Help Vampire!
C++ Super-FAQ - CppCon videos - C++14 latest draft (n3797) - C11 latest draft (n1570)
Boost - GCC 6.1.0 - Clang - GDB tutorial - Valgrind - Programming in 21 days
dis is my code, can u show me how to do to show the smallest value i ever enter, before exit??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)); }
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.