Number Patterns Example 8 – C Program

Number Patterns Example 8 – C Program

write a c program to display triangle number patterns example shows like below patterns.

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

#include <stdio.h>
#include<conio.h>

void 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");
    }

getch();
}

The output of number patterns c program is :

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

 

Leave a Reply

Your email address will not be published. Required fields are marked *