Write a program to give following output.....
*********
**** ****
*** ***
** **
* *
** **
*** ***
**** ****
*********
Answer Posted / prakash
int main()
{
int i, j, star, space, n, middle;
printf("Enter the max. number of stars in a line:");
scanf("%d", &n);
printf("Output:\n");
star = n/2;
space = 1;
middle = n/2 + 1;
for (j = 1; j <= n; j++)
printf("*");
printf("\n");
for (i = 2; i <= (n - 1); i++)
{
for (j = 1; j <= n; j++)
{
if ((j >= (star + 1)) &&
(j <= (star + space)))
{
printf(" ");
}
else
{
printf("*");
}
}
// calculate a and b
if (i < middle)
{
star -= 1;
space += 2;
}
else
{
star += 1;
space -= 2;
}
printf("\n");
}
for (j = 1; j <=n; j++)
printf("*");
printf("\n");
return 0;
}
| Is This Answer Correct ? | 1 Yes | 1 No |
Post New Answer View All Answers
What is pointer to pointer in c language?
Explain Function Pointer?
What is scanf () in c?
How are structure passing and returning implemented?
Are global variables static in c?
Why do we use stdio h and conio h?
find the sum of two matrices and WAP for it.
What does != Mean in c?
What does p mean in physics?
What is function definition in c?
Why is C language being considered a middle level language?
Why does notstrcat(string, "!");Work?
Write a program to reverse a given number in c?
Why is c used in embedded systems?
Is struct oop?