Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write C++ programs to perform the following tasks (A) -Require no more than 15 l

ID: 3864679 • Letter: W

Question

Write C++ programs to perform the following tasks (A) -Require no more than 15 lines of code. Ask user to enter 2 integer numbers from standard input. Find the smaller value of the two numbers. Check if the bigger value is odd or even number. Display the result per the sample below: SAMPLE INPUT/OUTPUT 1 Enter the First Number: 10 Enter the Second Number: 15 The bigger number is odd number 15. SAMPLE INPUT/OUTPUT Enter the First Number : 18 Enter the Second Number 11 The bigger numbers is even number 18. #include using namespace std; int main() {

Explanation / Answer

#include <iostream> // header file
using namespace std;
int main() //main function
{
   int num1,num2,max; //variable declaration

/*num1 stores 1st number

num2 stores 2nd number

max stores maximum of the two numbers*/


   printf("Enter the first number: "); //printing instruction to the user
   cin >>num1;//taking first number as input
   printf("Enter the second number: ");//asking for second input
   cin >> num2;//taking second input
  
   num1>num2 ? max=num1:max=num2; // using ( ?: ) statement check instead of if else

/* the execution of " boolean a? statement b: statement c ;"takes place in the following manner

1. it checks the if the value of boolean expression is true or not
2, if its true, the statement right after ? is executed, in the example case, statement b

3. If false, statement after : is executed. In this case statement C,

a?b:c is equivalent to

if(a)

b;

else

c;

*/
  

max%2==0?printf("Bigger number is Even "):printf("Bigger number is Odd "); //checking if max is odd or even
   return 0;
}

/*on removing the comments and unnecessary spaces, the above code is way lesser than 15 lines.*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote