C. Even, Odd, Positive and Negative – Codeforces Problem Solution in C

Disclaimer: Make sure you tried enough before checking the solution

Problem: https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/C

#include<stdio.h>
int main(){
    int a,b,i,ev=0,od=0,pos=0,neg=0,sum=0;
    scanf("%d",&a);
    for(i=1;i<=a;i++){
        scanf("%d",&b);
        if(b%2==0){
            ev++;
            sum = sum + ev;

        }
        if(b%2!=0){
            od++;
            sum = sum + od;
        }
        if(b>0){
            pos++;
            sum = sum + pos;
        }
        if(b<0){
            neg++;
            sum = sum + neg;
        }
    }
    printf("Even: %d\n",ev);
    printf("Odd: %d\n",od);
    printf("Positive: %d\n",pos);
    printf("Negative: %d\n",neg);
    return 0;
}

Assiut University Training – Newcomers solution

Leave a Comment