'C' program to arrange the even digits first and odd digits second of the given number vice versa.
Answers
Arrange even and odd digits:
Program:
#include<stdio.h> //include header file for using basic function
int main() //defining main method
{
int number,digit; //defining variables
printf(" Enter an integer number: "); //message
scanf("%d",&number); //input number by user
printf("The Even digits present in %d are \n",number); //print number
while(number>0) //loop for separating numbers
{
digit = number % 10; //contain remainder
number = number / 10; //contain quotient
if( digit % 2!= 0) //check condition
{
printf("\n The odd digit is: %d.",digit); //print odd number
}
else
{
printf("\n The even digit is: %d",digit); //print even number
}
}
return 0;
}
Output:
Enter an integer number: 786
The Even digits present in 786 are
The even digit is: 6
The even digit is: 8
The odd digit is: 7
Explanation:
- In the above C language program firstly header file is include then defines the main method. Inside the main method, two integer variable is declared that is "number, digit".
- The number variable is used for user input and the digit variable is checked even and odd number and prints its value.
- To find an even and odd number in digit a while loop defined that use digit variable for separate even and odd number and use conditional statement for print its value.
Learn more:
- what is even and odd number: https://brainly.in/question/8845878