hello again.
I have another problem that I am working on. I am to write a program so that it readsa series of integers, ending with EOF, and checks that the integers alternate betweenodd and even, with the first being odd. If there are no integers at all, that counts as "correct". The program prints "All OK" if the pattern is followed, and "Pattern not followed" if it's not.
my current code allows just checks if there is an odd integer in the input. So if i input 2 2 2 2 3 4 4 4, it prints All Ok. if there are no odd numbers then I get, "Pattern not followed."
Code:
#include <stdio.h>
int main () {
int val, odd, ok;
odd = 0;
ok = 1;
while (EOF != scanf("%d", &val)) {
odd = odd || val % 2;
ok = odd;
}
printf(ok ? "All OK\n" : "Pattern not followed\n");
return 0;
I would really like to figure this out on my own. I'm not asking anyone to write it for me, but I could really use some pointers. Thanks!