Pattern 40 : C Program to print the below number pattern using for loops

Spread the love

Write a C Program to print below number pattern on the console:

Enter how many rows you want : 5
 1
 2 4
 1 3 5
 2 4 6 8
 1 3 5 7 9

Note: This program is one of the Series of Number pattern programs in C.

Program to print number pattern:

  1. #include<stdio.h>
  2. int main()
  3. {
  4.    int i,j,k,n;
  5.    printf(“Enter how many rows you want : “);
  6.    scanf(“%d”,&n);

  7.    for(i=1;i<=n;i++)
  8.    {
  9.       if( i%2 == 0)
  10.          k=2;
  11.       else
  12.          k=1;
  13.  
  14.       for(j=1;j<=i;j++)
  15.       {
  16.          printf(” %d”,k);
  17.          k+=2;    // k=k+2
  18.       }
  19.       printf(n);
  20.    }
  21.    return 0;
  22. }

Output:


Similar Number Patterns:

Similar Star pattern programs :

Venkatesh Macha

Hi Guys, I am Venkatesh Macha. I am a programmer and an Open Source enthusiast, Presently working as a Software Engineer. Apart from that, I love to explore new technologies and things.

You may also like...

Leave a Reply