Saturday, 6 February 2016

Solution of 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.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
 int main()
{
    int a,b,c1=0,c2=0,c3=0,c4=0;
    for(a=1;a<=5;a++)
    {
        scanf("%d", &b);
        if(b%2==0) c1++;
        if(b%2==1||b%2==-1) c2++;
        if(b>0) c3++;
        if(b<0) c4++;
    }
    printf("%d valor(es) par(es)\n",c1);
    printf("%d valor(es) impar(es)\n",c2);
    printf("%d valor(es) positivo(s)\n",c3);
    printf("%d valor(es) negativo(s)\n",c4);

    return 0;
}

3 comments:

  1. #include
    int main ()
    {
    int a,b,par= 0,impar=0,positivo=0, negativo=0;

    for (a=1;a<=5;a++)
    {
    scanf ("%d", &b);
    if (b%2==0)
    {
    par++;
    }
    else
    {
    impar++;
    }
    if (b>0)
    {
    positivo++;
    }
    else if (b==0)
    {
    positivo = positivo;
    }
    else
    {
    negativo++;
    }
    }
    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", par,impar,positivo,negativo);
    return 0;
    }

    ReplyDelete
    Replies
    1. #include
      int main()
      {
      int a,b,c1=0,c2=0,c3=0,c4=0;
      for (a=0; a<5; a++)
      {
      scanf("%d",&b);
      if(b%2 == 0)
      c1++;
      if(b%2 == 1 || b%2 == -1)
      c2++;
      if(b>0)
      c3++;
      if(b<0)
      c4++;
      }
      printf("%d valor(es) par(es)\n",c1);
      printf("%d valor(es) impar(es)\n",c2);
      printf("%d valor(es) positivo(s)\n",c3);
      printf("%d valor(es) negativo(s)\n",c4);

      return 0;
      }

      THE RIGHT IS!

      Delete
  2. #include



    int main(){

    int n1,n2,n3,n4,n5;
    int vetor[5];
    int i,x;
    int par,impar,pos,neg;
    scanf("%d\n",&n1);
    scanf("%d\n",&n2);
    scanf("%d\n",&n3);
    scanf("%d\n",&n4);
    scanf("%d\n",&n5);
    vetor[0]=n1;
    vetor[1]=n2;
    vetor[2]=n3;
    vetor[3]=n4;
    vetor[4]=n5;
    x=0;
    pos=0;
    neg=0;
    impar=0;
    par=0;
    for(i=0;i<5;i++){
    x=vetor[i];
    //printf("%d",x);
    if (x>0){
    pos+=1;
    }
    if(x<0){
    neg+=1;
    }
    if(x%2==0||x==0){
    par+=1;
    }
    if (x%2!=0){
    impar+=1;
    }
    }
    printf("%d valor(es) par(es)\n",par);
    printf("%d valor(es) impar(es)\n",impar);
    printf("%d valor(es) positivo(s)\n",pos);
    printf("%d valor(es) negativos(s)\n",neg);
    return 0;
    }

    wrong answer 5%, i tried and cannot see the correct answer

    ReplyDelete

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