WAP to print even digits of a number.
Eg: Input-:5278 Output-: 2, 8
Input-: 437 Output-: 4
Answers
Answer:
#include<stdio.h>
int main(){
int num, digit, rem; // Declaring variables.
printf(" Enter a number: "); //Asking for input from user
scanf("%d",&num); //Taking input from user
printf("\n The Even digits present in %d are \n",num);
while(num>0) // Loop to check even digits
{
digit = num % 10; //It will give the last digit's value to "digit"
num = num / 10; //It will truncate the last digit and hence, removing last digit
rem = digit % 2; //it will give remainder after dividing by 2
if(rem == 0) //it will check if the remainder is 0 OR the digit is perfectly divisible by 2 OR the digit is even.
printf("\n %d.",digit); // It will print the number stored in "digit"
}
return 0; // It will return a number because the main's return type is "int"
}