Create a program based on the sample output using the do-while loop.
--Choices--
1-EVEN 2-ODD 3-EXIT
Enter Your Choice Above : 2
Enter a Number : 16
Odd Numbers : 1 3 5 7 9 11 13 15
Enter Your Choice Above : 1
Enter a Number : 8
Odd Numbers : 2 4 6 8
Enter Your Choice Above : 2
Enter a Number : 0
Your Program is about to exit...
Thank You!
#include <stdio.h>
int main() {
int num;
int num2;
int start;
do
{
printf("\n1-EVEN 2-ODD 3-EXIT\nEnter Your Choice Above: ");
scanf("%d", &num);
if (num != 0 && num != 3) {
printf("\nEnter a Number: ");
scanf("%d", &num2);
if (num == 1) {
printf("Even numbers: ");
for (int i = 2; i <= num2; i+=2) {
printf("%d ", i);
}
} else if (num == 2){
printf("Odd numbers: ");
for (int i = 1; i <= num2; i+=2) {
printf("%d ", i);
}
}
}
}while(num != 0 && num != 3);
printf("Your Program is about to exit...\nThank You!\n");
return 0;
}
Comments
Thank You!
Leave a comment