Tuesday, 8 March 2011

Print the following triangle

Print the following triangle.
a b c d e
  a b c d
    a b c
      a b
        a

#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,j,k;
clrscr();
printf("Enter the number : ");
scanf("%d",&n);
printf("\n");
for(i=0;i<n;i++)
{
for(k=1;k<=i;k++)
{
printf(" ");
}
for(j=1;j<=n-i;j++)
{
printf(" %c",96+j);
}
printf("\n");
}
getch();
return 0;
}
Output:
Enter the number : 5
a b c d e
  a b c d
   a b c
    a b
     a

No comments:

Post a Comment