Predicate Macros
Completed
Define IS_EVEN(n), IS_VOWEL(c) (lower-case only) and IS_DIGIT(c) macros. Read a word and print how many characters are vowels, how many are digits, and whether its length is even.
Input
One word.
Output
One line: vowels=V digits=D even=yes|no
Example
Input
education2026
Output
vowels=5 digits=4 even=no
Editor
C
Hints
Macros that evaluate to 1 or 0 can be used directly in if conditions.
Solution explanation
Beware: a macro argument is evaluated every time it appears, so never pass something like c++.
Show solution
#include <stdio.h>
#include <string.h>
#define IS_EVEN(n) ((n) % 2 == 0)
#define IS_VOWEL(c) ((c) == 'a' || (c) == 'e' || (c) == 'i' || (c) == 'o' || (c) == 'u')
#define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
int main() {
char w[100];
int vowels = 0, digits = 0;
scanf("%s", w);
for (int i = 0; w[i] != '\0'; i++) {
if (IS_VOWEL(w[i])) vowels++;
if (IS_DIGIT(w[i])) digits++;
}
printf("vowels=%d digits=%d even=%s\n", vowels, digits, IS_EVEN((int) strlen(w)) ? "yes" : "no");
return 0;
}