URI Online Judge Solution 1066 Even, Odd, Positive and Negative using C Programming Language.
Make a program that reads five integer values. Count how many of these values are even, odd, positive and negative. Print these information like following example.
Make a program that reads five integer values. Count how many of these values are even, odd, positive and negative. Print these information like following example.
Input
The input will be 5 integer values.
Output
Print a message like the following example with all letters in lowercase, indicating how many of these values are even, odd, positive and negative.
| Input Sample | Output Sample | 
-5 
0 -3 -4 12  | 
3 valor(es) par(es) 
2 valor(es) impar(es) 1 valor(es) positivo(s) 3 valor(es) negativo(s)  | 
Solution using C :
#include <stdio.h>
int main() {
    int num[5],e,o,p,n,i;
    e = o = p = n = 0;
    for(i=0; i<5; i++)
    {
        scanf("%d",&num[i]);
        if(num[i]%2 == 0)
            e++;
        else
            o++;
        if(num[i]>0)
            p++;
        else if(num[i]<0)
            n++;
    }
    printf("%d valor(es) par(es)\n%d valor(es) impar(es)\n%d valor(es) positivo(s)\n%d valor(es) negativo(s)\n",e,o,p,n);   
    return 0;
} 


Comments
Post a Comment