One simple algorithm problem is finding the largest or smallest numbers, where numbers are entered by the user. For example, look for the largest or smallest numbers among the 3 pieces of number of input by the user. We can answer these questions and look for the largest or smallest numbers using the service conditions are available in C + + programming language.
But generally to seek the largest or smallest numbers like this, the programmer will use the IF statement because it is easier to understand and more flexible. For more details, please refer to C + + program below to find the largest numbers:
But generally to seek the largest or smallest numbers like this, the programmer will use the IF statement because it is easier to understand and more flexible. For more details, please refer to C + + program below to find the largest numbers:
# Include <iostream> # Include <conio.h> void main () { court <<"Program Seeking Numbers Greatest" <<endl; int bil1, bil2, bil3, the largest; court <<"Enter number 1:"; cin>> bil1; court <<"Enter number 2:"; cin>> bil2; court <<"Enter number 3:"; cin>> bil3; if (bil1> bil2) largest = bil1; else largest = bil2; if (bil3> biggest) largest = bil3; court <<"Biggest number =" <<largest; getch (); } |
Explanation of the program to find the largest numbers:
Initially the program will prompt the user to enter three numbers that bil1, bil2 and bil3. Then the program will compare between bil1 and bil2, if it turns out bil1 larger, it is considered the biggest stuffed with bil1 value, if otherwise then terbesardiisi with bil2. Next live compare between bil3 with the largest, if turns out bil3 bigger than the biggest, the greatest value is replaced again with bil3 value.
In the end the largest will be filled with the largest number among the three numbers entered by the user. As an exercise, please modify the above program for a program to find the largest number among the 4 fruit number that entered by the user. Good luck, if you do not succeed and the curious way, please contact me at wirautama06 [at] yahoo.com.
Initially the program will prompt the user to enter three numbers that bil1, bil2 and bil3. Then the program will compare between bil1 and bil2, if it turns out bil1 larger, it is considered the biggest stuffed with bil1 value, if otherwise then terbesardiisi with bil2. Next live compare between bil3 with the largest, if turns out bil3 bigger than the biggest, the greatest value is replaced again with bil3 value.
In the end the largest will be filled with the largest number among the three numbers entered by the user. As an exercise, please modify the above program for a program to find the largest number among the 4 fruit number that entered by the user. Good luck, if you do not succeed and the curious way, please contact me at wirautama06 [at] yahoo.com.