To Print The Following Pattern
Program in C:
int main()
{
int star = 0, space = 5;
for (int i=1;i<=9;i++)
{
if(i<=5)
{
space--;
star++;
}
else
{
space++;
star--;
}
for (int j=1;j<=space;j++)
printf(" ");
for (int k=1;k<=star;k++)
printf("*");
for(int l=1;l<=8;l++)
{
if(i<=3 || i>6)
printf(" ");
else
printf("*");
}
for (int m=1;m<=star;m++)
printf("*");
printf("\n");
}
return 0;
}
Program in JAVA:
public static void main(String [] args)
{
int star = 0, space = 5;
for (int i=1;i<=9;i++)
{
if(i<=5)
{
space--;
star++;
}
else
{
space++;
star--;
}
for (int j=1;j<=space;j++)
System.out.print(" ");
for (int k=1;k<=star;k++)
System.out.print("*");
for(int l=1;l<=8;l++)
{
if(i<=3 || i>6)
System.out.print(" ");
else
System.out.print("*");
}
for (int m=1;m<=star;m++)
System.out.print("*");
System.out.println(" ");
}
}
}
No comments:
Post a Comment