C/C++ Program to print the following output using Loop
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
Program
#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,k;
clrscr();
printf("Enter the number:");
scanf("%d", &n);
for(i=1; i<n; i++)
{
for(j=1; j<n-i; j++)
{
printf ("_");
}
for(k=1;k<=i;k++)
{
printf ("*_");
}
printf("\n");
}
for(i=1, i<=n; i++) // for printing
{
for(m=1;m<=i; m++)
{
printf (" ");
}
for (k=n-i; k>=1;k--)
{
printf("* ");
}
printf ("\n");
}
getch();
}
Click here to check the output
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
Program
#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,k;
clrscr();
printf("Enter the number:");
scanf("%d", &n);
for(i=1; i<n; i++)
{
for(j=1; j<n-i; j++)
{
printf ("_");
}
for(k=1;k<=i;k++)
{
printf ("*_");
}
printf("\n");
}
for(i=1, i<=n; i++) // for printing
{
for(m=1;m<=i; m++)
{
printf (" ");
}
for (k=n-i; k>=1;k--)
{
printf("* ");
}
printf ("\n");
}
getch();
}
Click here to check the output
No comments:
Post a Comment