Friday, 4 March 2016

Solution of URI 1074 :: Even or Odd


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.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int N,X,a;
    scanf ("%d", &N);
    for(a=1;a<=N;a++)
    {
        scanf ("%d",&X);
        if(X==0)
            printf("NULL\n");
        else if(X<=0&&X%2==0)
            printf ("EVEN NEGATIVE\n");
        else if(X<=0&&X%2==-1)
            printf ("ODD NEGATIVE\n");
        else if(X>=0&&X%2==0)
            printf ("EVEN POSITIVE\n");
        else if(X>=0&&X%2==1)
            printf ("ODD POSITIVE\n");
    }
    return 0;
}

4 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. #include
    int main()
    {
    int a,b,c;
    scanf("%d",&c);

    for(b=1;b<=c;b++){
    scanf("%d",&a);
    if(a==0)
    {
    printf("NULL\n");
    }

    else if (a>0&&a%2==0){
    printf("EVEN POSITIVE\n");
    }
    else if (a>0&&a%2==1){
    printf("ODD POSITIVE\n");
    }
    else if (a<0&&a%2==0){
    printf("EVEN NEGETIVE\n");
    }
    else if (a<0&&a%2==-1){
    printf("ODD NEGETIVE\n");
    }


    }

    return 0;
    }
    whats wrong

    ReplyDelete
  3. #include
    int main()
    {
    int i,j,k[100];
    scanf("%d",&j);
    for(i=0; i0)
    printf("EVEN POSITIVE\n");
    else
    printf("EVEN NEGATIVE\n");
    }
    else if(k[i]%2!=0)
    {
    if(k[i]>0)
    printf("ODD POSITIVE\n");
    else
    printf("ODD NEGATIVE\n");
    }
    }
    }

    ReplyDelete

Note: only a member of this blog may post a comment.