C++ Program Operations On Odd Input Number By The User - Wisdom Lighter

Sunday, 1 July 2018

C++ Program Operations On Odd Input Number By The User

When the user enters an odd number, program changes its value to 3 times the entered number plus 1. Otherwise, changes its value to half of the number entered.


#include <iostream.h>
#include <stdio.h>
#include <conio.h>

void main ()

{
   Clrscr();

   int currentNumber ;
   cout << "Please Enter the Number " << endl;
   cin >> currentNumber ;
   if (currentNumber %2 != 0) {

    currentNumber = currentNumber * 3 + 1 ;
    cout << "    " << endl;
    cout << "answer = " << currentNumber  << endl;

   } else {

   currentNumber = currentNumber/2 ;
   cout << "    " << endl;
   cout << "answer = " << currentNumber  << endl;

   }
   getch();
}

No comments:
Write comments