Friday, 4 March 2016

Solution of URI 1070 :: Six Odd Numbers


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 X,a,b;
    scanf("%d", &X);
    if(X%2==0)
    {
        for(a=X+1;a<=X+11;a=a+2)
            printf("%d\n",a);
    }
    else
    {
        for(b=X;b<=X+10;b=b+2)
            printf("%d\n",b);
    }
    return 0;
}

6 comments:

  1. More simple!

    int main(){
    int num=0;
    scanf("%d",&num);

    for (int i=1; i<=11; i++){
    num++;
    if(num%2!=0){
    printf("%d\n",num);

    }

    }

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. #include
    int main()
    {
    int n;
    int i;
    int cnt=0;
    scanf("%d",&n);
    for(i=n; cnt<6; i++){
    if(i%2==1){
    printf("%d\n",i);
    cnt++;
    }

    }

    return 0;
    }

    ReplyDelete
  4. Replies
    1. cause you need more 5 odd number like
      if x=2
      then x=2+1
      if you add 11 you get 5 more odd number 5,7,9,11,13

      Delete
  5. #include
    int main()
    {
    int x,i;
    scanf("%d",&x);

    if(x%2!=0)
    {
    for(i=0;i<6;i++)
    {
    x=x+2;
    printf("%d\n",x);
    }
    }
    else
    {
    x--;
    for(i=0;i<6;i++)
    {
    x=x+2;
    printf("%d\n",x);
    }
    }
    return 0;
    }

    ReplyDelete

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