Saturday, January 26, 2013

Write a C++ program to arrange 10 numbers in ascending order

Exercise 2)
Write a C++ program and call it sortcheck.cpp which receives 10 numbers from input and checks whether these numbers are in ascending order or not. You are not allowed to use arrays. You should not define more than three variables.

e.g    Welcome to the program written by Your Name:
Please enter 10 Numbers: 12 17 23 197 246 356 790 876 909 987
Fine, numbers are in ascending order.

Solution-


#include<iostream>
#include<cmath>

using namespace std;

int main()
{
    char redo;
    double a,b,d;
    
 do
    {  
           d=1; 
//--------Printing my name on screen----------------    
    cout<<"Welcome to the  program  written by Your Name"<<endl;
    cout<<"***************************************************************"<<endl;
    cout<<endl<<endl<<endl;
    //----receiving the variables from input--------------         
    cout<<" Please enter the ten values to know the result";
    cout<<endl;
    cin>>a>>b;
// if condition is introduced to check the sort sequence
         if(a<b)
        {
               
         a=b;
         d=d+1;
         
         }
//once again the the place at b is empty so required new no. fo variable b         
          cin>>b;
           if(a<b)
        {
               
         a=b;
         d=d+1;
                  
         }
//once again the the place at b is empty so required new no. fo variable b          
          cin>>b;
             if(a<b)
        {
               
         a=b;
         d=d+1;
           
         }
//once again the the place at b is empty so required new no. fo variable b          
          cin>>b;
             if(a<b)
        {
               
         a=b;  
         d=d+1;
            
         }
//once again the the place at b is empty so required new no. fo variable b          
          cin>>b;
             if(a<b)
        {
               
         a=b;  
         d=d+1;
       
         
         }
//once again the the place at b is empty so required new no. fo variable b          
          cin>>b;
             if(a<b)
        {
               
         a=b;
         d=d+1;
                
         }
          cin>>b;
//once again the the place at b is empty so required new no. fo variable b           
             if(a<b)
        {
               
         a=b; 
         d=d+1;
            
         }
          cin>>b;
//once again the the place at b is empty so required new no. fo variable b           
             if(a<b)
        {
               

         d=d+1;
                  
         }
          cin>>b;
//once again the the place at b is empty so required new no. fo variable b           
             if(a<b)
        {
               
         a=b;
         d=d+1;
              
         }
         cout<<endl;
//here we print how many times the new no. is entered is greater then earlier value         
       cout<<"number of currect ascending values entered is="<<d<<endl<<endl;
       // Here we print the result
           if(d==10){
               cout<<"Fine,the numbers are in ascending order."<<endl<<endl;
               }
               else{
           
         cout<<"Fine,the numbers are not in ascending order."<<endl<<endl;  
                        }
      cout<<"enter y or Y to continue:";
           cin>>redo;
           cout<<endl<<endl;
           }
           while(redo=='y'||redo=='Y');
                        
          
          
                       
     system("pause");
    return 0;
    
}



---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------




---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------

IT Certification Category (English)640x480

Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com


Top Online Courses From ProgrammingKnowledge

Python Course http://bit.ly/2vsuMaS
Java Coursehttp://bit.ly/2GEfQMf
Bash Coursehttp://bit.ly/2DBVF0C
Linux Coursehttp://bit.ly/2IXuil0
C Course http://bit.ly/2GQCiD1
C++ Coursehttp://bit.ly/2V4oEVJ
PHP Coursehttp://bit.ly/2XP71WH
Android Coursehttp://bit.ly/2UHih5H
C# Coursehttp://bit.ly/2Vr7HEl
JavaFx Coursehttp://bit.ly/2XMvZWA
NodeJs Coursehttp://bit.ly/2GPg7gA
Jenkins Course http://bit.ly/2Wd4l4W
Scala Coursehttp://bit.ly/2PysyA4
Bootstrap Coursehttp://bit.ly/2DFQ2yC
MongoDB Coursehttp://bit.ly/2LaCJfP
QT C++ GUI Coursehttp://bit.ly/2vwqHSZ