Search C Program

Number Pattern - 17

1
2 4
1 3 5
2 4 6 8
1 3 5 7 9

#include<stdio.h>
int main()
{
  int i,j,k;
  for(i=1;i<=5;i++)
  {
    if(i%2==0) 
    {
      k=2; 
    }
    else 
    {
      k=1;
    }
    for(j=1;j<=i;j++,k+=2)
    {
      printf("%d ", k);
    }
    printf("\n");
  }
  return 0;
}


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


9 comments:

  1. void main()
    { clrscr();
    int i,j;
    for(i=1;i<=5;i++)
    { if(i%2==1)
    { for(j=1;j<=i*2;j=j+2)
    printf("%d",j);
    }
    else
    { for(j=2;j<=i*2;j=j+2)
    printf("%d",j);
    }
    printf("\n");
    }

    getch();
    }

    ReplyDelete
  2. Int main()
    {
    Int I, j;
    For(i=1;i<=5;i++)
    {
    For(j=1;j<=i;j++)
    {
    If(i%2==0)
    {
    Pf("%d",2j);
    }
    Else
    {
    Pf("%d",2j-1);
    }
    }
    Pf("\n");
    }
    Return 0 ;
    }

    ReplyDelete
  3. could not understand line 15. but the code is pretty correct.

    ReplyDelete
  4. Replies
    1. public class Shape
      {
      public static void main() {
      for(int i = 1;i <= 5;i++) {
      int k = 0;
      if(i % 2 == 0) {
      k = 2;
      }
      else {
      k = 1;
      }
      for(int j = k;j <= (2*i);j+=2) {
      System.out.print(j+" ");
      }
      System.out.println();
      }
      }
      }

      Here you go... lol

      Delete
  5. #include
    int main ()
    {
    int i,j,n,k;
    printf ("Enter the value of n:");
    scanf ("%d",&n);
    for (i=1;i<=n;i++)
    {
    if(i%2==1)
    k=-1;
    else
    k=0;
    for (j=1;j<=i;j++)
    {
    printf ("%d",k+=2);
    }
    printf ("\n");
    }
    }

    ReplyDelete
  6. #include

    int main()
    {
    int r,i,j;

    printf("Enter the no. of rows : ");
    scanf("%d",&r);

    for(i=1;i<=r;i++)
    {
    for(j=(i+1)%2+1;j<=(2*i)-(i%2);j+=2)
    {
    printf("%d ",j);
    }
    printf("\n");
    }
    }

    ReplyDelete
  7. #include
    void main()
    {
    int i,j;
    for(i=1;i<=9;(i%2 != 0)?i+=3:i++)
    {




    if(i%2 != 0)
    {
    for(j=1;j<=i;j+=2)
    {
    printf("%d",j);
    }
    }
    else
    {
    for(j=2;j<=i;j+=2)
    {
    printf("%d",j);
    }
    }
    printf("\n");
    }

    }

    ReplyDelete