Sunday, July 16, 2017

Beginner problem URI 1066 -> Even, Odd, Positive and Negative

Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.



#include<stdio.h>
int main()
{
    int num, i, oddcnt=0, evcnt=0, poscnt=0, negcnt=0;

    for(i=1; i<=5; i++){
        scanf("%d",&num);

        if(num % 2 == 0)
            evcnt++;
        if(num%2 == 1 || num%2 == -1)
            oddcnt++;
        if(num > 0)
            poscnt++;

        if(num < 0)
            negcnt++;

    }
        printf("%d valor(es) par(es)\n",evcnt);
        printf("%d valor(es) impar(es)\n",oddcnt);
        printf("%d valor(es) positivo(s)\n",poscnt);
        printf("%d valor(es) negativo(s)\n",negcnt);

    return 0;
}

No comments:

Post a Comment

কম্পিউটার প্রোগ্রামিং শেখা কতটা গুরুত্বপূর্ণ ?

প্রোগ্রামিং কতটা গুরুত্বপূর্ণ? কম্পিউটার বিজ্ঞানের অনেক বড় একটা অংশ জুড়েই রয়েছে প্রোগ্রামিংয়ের দখল। প্রোগ্রামিং ছাড়া আমর...