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; }
- C++ Simple Programs And Examples
- C++ – Hello World Program
- C++ – Simple calculator
- C++ – Even and Odd
- C++ – Swap two numbers
- C++ – Prime Number
- C++ – Find Perfect Number
- C++ – Factorial of Number
- C++ – Fibonacci Series
- C++ – Human Resource Management Program
- C++ – Calculate number of characters, words, sentences
- C++ – Subtract two Strings
- C++ – Processing of the Students structure
- C++ – Program with Matrices
- C++ – Calculate Equation
- C++ – Arrange Numbers in Ascending order
- C++ – Check Armstrong Number
- C++ – HCF and LCM
- C++ – Square Root of a Number
- C++ – Cube Root of a Number
- C++ – ASCII Code for Characters and numbers
- C++ – Check Palindrome Number
- C++ – Bubble sort
- C++ – Random Number Generator
- C++ – Sum of ODD Numbers in the Given Range
- C++ – Display current date and time
Leave a Reply