Pages

Friday, July 1, 2016

C Program to Print given number Pattern.


C Program to Print Number Pattern as given below:
For N=5,

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

#include<stdio.h>
int main()
{
 int i, j, n=5;

 for(i=0; i<5; i++) //this loop tracks no. of lines
 {
  for(j=0; j<=i; j++)//this loop tracks numbers in a row
  {
    printf("%d ",j+1); //this line prints a number
  }
    printf("\n");
 } 
 return 0;
}

Output of program

1
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5

 

No comments:

Post a Comment