Write a C Program to Print Number Triangle
Program:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,j,k,l,n;
system("cls");
printf("Enter the range=");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
printf(" ");
}
for(k=1;k<=i;k++)
{
printf("%d",k);
}
for(l=i-1;l>=1;l--)
{
printf("%d",l);
}
printf("\n");
}
return 0;
}
Output:
Enter the range=
6
1
121
12321
1234321
123454321
12345654321
--------------------------------
Process exited after 7.007 seconds with return value 0
Press any key to continue . . .
Program:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,j,k,l,n;
system("cls");
printf("Enter the range=");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
printf(" ");
}
for(k=1;k<=i;k++)
{
printf("%d",k);
}
for(l=i-1;l>=1;l--)
{
printf("%d",l);
}
printf("\n");
}
return 0;
}
Output:
Enter the range=
6
1
121
12321
1234321
123454321
12345654321
--------------------------------
Process exited after 7.007 seconds with return value 0
Press any key to continue . . .
0 Comments:
Post a Comment