9 Jan 2015

Program: Create the following triangle 1 1 2 1 1 2 3 2 1



#include<stdio.h>
#include<conio.h>
void main()
{
int  i,j,n,p;
clrscr();
printf("Enter the number of  row:-\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
  for(j=1;j<=n-i;j++)
   printf(" ");
  for(p=1;p<=i;p++)
   printf("%d",p);
  for(p=i-1;p>=1;p--)
   printf("%d",p);
  printf("\n");
}
getch();
}

No comments:

Post a Comment