Last active
December 7, 2021 13:30
-
-
Save mjcarnaje/74895e609a2ee22c2eba39d6fac934b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void odd_numbers(int first, int second) | |
{ | |
for (int i = first; i <= second; i++) | |
{ | |
if (i % 2 != 0) | |
{ | |
printf("%d ", i); | |
} | |
} | |
} | |
void even_numbers(int first, int second) | |
{ | |
for (int i = first; i <= second; i++) | |
{ | |
if (i % 2 == 0) | |
{ | |
printf("%d ", i); | |
} | |
} | |
} | |
int main() | |
{ | |
int first, second, type; | |
int invalid_count = 0; | |
printf("Enter a number: "); | |
scanf("%d", &first); | |
printf("Enter another number: "); | |
scanf("%d", &second); | |
if (first >= second) | |
{ | |
printf("\nInvalid input range.\n"); | |
return 0; | |
} | |
do | |
{ | |
if (invalid_count > 0) | |
{ | |
printf("\nInvalid input.\n"); | |
} | |
printf("Enter [1] to use display even [2] to display odd: "); | |
scanf("%d", &type); | |
invalid_count++; | |
} while (type != 1 && type != 2); | |
if (type == 1) | |
{ | |
printf("\nEven numbers between %d and %d:\n", first, second); | |
even_numbers(first, second); | |
} | |
else if (type == 2) | |
{ | |
printf("\nOdd numbers between %d and %d:\n", first, second); | |
odd_numbers(first, second); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment