Untitled

 avatar
unknown
plain_text
4 years ago
511 B
4
Indexable
#include <stdio.h>
#include <stdlib.h>

int main(voi)
{

    /// TA Solution
    char num_string;
    int odd = 0, even = 0;
    int i = 0;

    printf("Enter a string of numbers ending with '#': ");
    while(scanf("%c", &num_string) && num_string != '#'){
        if(num_string % 2 == 0){
            even++;
        }
        else{
            odd++;
        }
        i++;
    }
    printf("There are %d odd numbers and %d even numbers in the string.\n", odd, even);

    return 0;
}
Editor is loading...