Code Box
-----------------------------------------
/*program to print number pattern by for loop
1
21
321
4321
54321
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,k;
clrscr();
printf("\nEnter a number: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=n;j>i;j--)
{
printf(" ");
}
for(k=i;k>=1;k--)
{
printf("%d",k);
}
printf("\n");
}
getch();
}
-----------------------------------------
/*program to print number pattern by for loop
1
21
321
4321
54321
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,k;
clrscr();
printf("\nEnter a number: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=n;j>i;j--)
{
printf(" ");
}
for(k=i;k>=1;k--)
{
printf("%d",k);
}
printf("\n");
}
getch();
}
No comments:
Post a Comment