Search C Program | nimishsoft@gmail.com

Series Program - 10

1 2 3 6 9 18 27 54...
int main()
{
    int a=1,b=2,i,n=10;
    printf("%d %d ",a, b);
    for(i=3;i<=n;i++)
    {
        if(i%2==1)
        {
            a=a*3;
            printf("%d ",a);
        }
        else
        {
            b=b*3;
            printf("%d ",b);
        }
    }
    return 0;
}


Related Links:
- More Series Programs
- Number Pattern Programs
- Star Pattern Programs in C
- Alphabet Pattern Programs in C

6 comments:

  1. 1+2=3 ok
    but how come 2+3=6, is should be 5 there.

    ReplyDelete
    Replies
    1. it is multiplication

      Delete
    2. This sequence is computed by adding the value to itself if it is odd, and by adding the previous value to it if it is even.

      Delete
  2. Vishwajeet Kumar SinghSeptember 9, 2018 at 11:09 PM

    for(i=0;i<=20;i++)
    {
    if(a%2!=0) //all the odd positions like 1,3,5 have 0,2,4 so i-1
    {
    a=i-1;
    printf("%d",a);
    }
    else
    {
    a=(i/2-1)*3; // nos in even positions have common difference 3 so (*3)
    printf("%d",a);
    }
    }

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

    ReplyDelete
  4. ADD EVEN DIGIT NUMBERS WITH +3 AND FOR ODD ONES ITS +2

    ReplyDelete