1. Asks the user to enter a positive integer greater than or equal to 0 2. Valid
ID: 3669857 • Letter: 1
Question
1. Asks the user to enter a positive integer greater than or equal to 0
2. Validates that the entry is a positive integer greater than or equal to 0 3
. Displays the even digits that make up the number entered by the user (assume zero be even)
4. The digits must all be in a single line and separated by a space
5. If no even digits make up the number, then a message indicating that there are no even digit must be displayed
6. The user must be asked if he/she wants to continue entering numbers for numbers or quit.
Explanation / Answer
#include<stdio.h>
#include<conio.h>
void main()
{
int num;
char ch;
int i=0;
do{
printf("enter a positive number greater than or equal to 0 :")
scanf("%d",&num);
if(num>=0)
{
while(i<=num)
{
printf("%d ", i);
i += 2;
}
if(i<=0)
printf("There are no even numbers in the range");
}
else
{
printf("The number you enterd is less than 0");
}
printf ("Do you want to continue: y/n");
ch = getchar();
getchar();
} while(ch == 'y');
}
}
Note :- Used do while to acheive the last 6th ponit to repaeat the code in user need
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.