Write a program to print the following outputs using for loops.
(a) 1 (b) * * * * *
2 2 * * * *
3 3 3 * * *
4 4 4 4 * *
5 5 5 5 5 *
#include <stdio.h>
void main()
{
int x,i;
clrscr();
for(i=1;i<=5;i++)
{
for(x=1;x<=i;x++)
{
printf("%d",i);
}
putchar('\n');
}
putchar('\n');
for(i=5;i>=1;i--)
{
for(x=i;x>=1;x--)
{
putchar('*');
}
putchar('\n');
}
getch();
}
(a) 1 (b) * * * * *
2 2 * * * *
3 3 3 * * *
4 4 4 4 * *
5 5 5 5 5 *
#include <stdio.h>
void main()
{
int x,i;
clrscr();
for(i=1;i<=5;i++)
{
for(x=1;x<=i;x++)
{
printf("%d",i);
}
putchar('\n');
}
putchar('\n');
for(i=5;i>=1;i--)
{
for(x=i;x>=1;x--)
{
putchar('*');
}
putchar('\n');
}
getch();
}
No comments:
Post a Comment