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
shorting algorithmS
What is meant by operator precedence?
what is use of malloc and calloc?
if a is an integer variable, a=5/2; will return a value a) 2.5 b) 3 c) 2 d) 0
Can math operations be performed on a void pointer?
why we wont use '&' sing in aceesing the string using scanf
Differentiate abs() function from fabs() function.
can we have joblib in a proc ?
What is difference between scanf and gets?
Do you know the use of fflush() function?
Explain what is the difference between functions abs() and fabs()?
What is static volatile in c?
What is the use of typedef in structure in c?
Why is sprintf unsafe?
What is c definition?