Computer Science, asked by debnatha823, 11 months ago

Write a program to input and count the number of digits.The program further checks whether the number contains odd number of digits or even number of digits.
Sample Input:749
Sample Output:Number of digits=3
The number contains odd number of digits

Answers

Answered by cjaya
11

Answer:

here's the answer in the attachment above

Attachments:
Answered by codiepienagoya
3

Following are even or odd number program can be defined as follows:

Output:

Input: 749

Number of digits= 3

The number contains odd number of digits

Explanation:

following are the program to this question:

Program:

#include <iostream> //defining header file

using namespace std;

int main() //defining main method

{

int x,i,j=0; //defining integer variable

cout<<"Input: "; //print message

cin>> x; //input value

while(x!=0) //defining loop to calculate digites

{

   i=x%10; //holding remainder value

   x=x/10; //holding quotient value

   j++; // increment value j by 1

}

cout<<"Number of digits= "<<j<<endl; //print total number of digite

if(j%2==0) //check even number condition

{

cout<<"The number contains even number of digits";  //print message

}

else //else block

{

cout<<"The number contains odd number of digits";   //print message

}

   return 0;

}

Description to the above program can be given as follows:

  • In the above program, the first main method is declared, inside the method three integer variable "x, i, and j" is declared, in which variable "x" is used to take input from the user, and then we declared a while loop.
  • Inside the variable "i and j" is used that counts the total number of digits, then define the conditional statement, in which we check variable j value is even or odd.
  • If the condition is true it will print number is even, else it will print an odd number.

Learn more:

  • Even/Odd: https://brainly.in/question/13700138
Similar questions