exercising the freedom of expression.
  • Let Your Mind Speak

    Let Your Mind Speak blog is all about anything, everything that crashes my mind. It's a collection of hiddeous and most craziest things that my brain process everyday.

  • Pinoyxtreme Forum

    PinoyXtreme Forum provides free downloads on various things. It also allows users to join competitions on various SOTW and GFX Battles via PXDesignz.

  • Symbianize

    Symbianize is a community forum offers free downloads on various items. It also offers chit-chats, help and request sections. And many more.

Showing posts with label Source Code. Show all posts
Showing posts with label Source Code. Show all posts

Friday, October 17, 2014

Posted by Super Aykin | Friday, October 17, 2014 | No comments


The program will sort 3 numbers in ascending or descending order. The code will be like this.
//sorting 3 number.. from lowest to highest digit or vice versa
//for educational purposes only

#include <iostream>
using namespace std;
int main()
{
    
    int num1, num2, num3;
    int min, ave, max;
    
    char ans;
    char ans1;
    
    while (ans != 'y')
    {
    cout<<"Enter 3 numbers:"<<endl;
    cin>>num1>>num2>>num3;
    
    cout<<endl<<endl<<endl<<endl<<endl;
    
    if (num1 > num2)
    {
             if (num1 > num3)
             {
                      if (num2 > num3)
                      {
                               max = num1;
                               ave = num2;
                               min = num3;
                      }
                      else
                      {
                               max = num1;
                               ave = num3;
                               min = num2;
                      }
             }
             else
             {
                      max = num3;
                      ave = num1;
                      min = num2;
             }
    }
    else
    {
             if (num2 > num3)
             {
                      if (num1 > num3)
                      {
                               max = num2;
                               ave = num1;
                               min = num3;
                      }
                      else
                      {
                               max = num2;
                               ave = num3;
                               min = num1;
                      }
             }
             else
             {
                      max = num3;
                      ave = num2;
                      min = num1;
             }
    }
    
    cout<<"Key in 'a' for ascending order or 'd' for descending order: ";
    cin >> ans1;
    cout<<endl<<endl<<endl<<endl<<endl;
    
    if (ans1 == 'a')
    {
             cout<<"Sorted to: "<<min<<" "<<ave<<" "<<max<<endl<<endl<<endl<<endl<<endl;
    }
    else
    {
             cout<<"Sorted to: "<<max<<" "<<ave<<" "<<min<<endl<<endl<<endl<<endl<<endl;
    }
    
    cout<<"Type ""y"" to quit. or type any letter to try again: ";
    cin>>ans;
    cout<<endl<<endl<<endl;
                         
}                  
    
    return 0;
}