C Write a block of statements like a function but you dont h

(C++) Write a block of statements (like a function, but you don\'t have to write it like a function) that take three arguments of type int and returns true if the arguments are in ascending order; otherwise, it returns false. No arrays, only using if...else / do.....while / while / for ... etc statements to write this code.

Thank you!

Solution

#include<iostream>
using namespace std;
//Prototype of the function
bool check(int, int, int);
int main()
{
int a, b, c;
bool r;
//Accept data
cout<<\"\ Enter 3 numbers: \";
cin>>a>>b>>c;
//Function call for check the order
r = check(a, b, c);
//Display the result
if(r == true)
cout<<\"Numbers \"<<a<<\" \"<<b<<\" \"<<c<<\" In ascending order\";
else
cout<<\"Numbers \"<<a<<\" \"<<b<<\" \"<<c<<\" In not in ascending order\";
}
//Function to check the order
bool check(int a, int b, int c)
{
//If the first number is less than the second and third
if(a < b && a < c)
{
//If second number is less than the third
if(b < c)
return true;
}
else
return false;
}

Output 1:

Enter 3 numbers:

12
15
17
Numbers 12 15 17 In ascending order

Output 2:

Enter 3 numbers:

18
10
12
Numbers 18 10 12 In not in ascending order

Output 3:

Enter 3 numbers:

10
20
5
Numbers 10 20 5 In not in ascending order

(C++) Write a block of statements (like a function, but you don\'t have to write it like a function) that take three arguments of type int and returns true if t
(C++) Write a block of statements (like a function, but you don\'t have to write it like a function) that take three arguments of type int and returns true if t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site