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 the difference between the local variable and global variable in c?
What are the 5 types of organizational structures?
Why does the call char scanf work?
#include main() { enum _tag{ left=10, right, front=100, back}; printf("left is %d, right is %d, front is %d, back is %d",left,right,front,back); }
What are the types of unary operators?
Explain what is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?
What is the difference between malloc() and calloc() function in c language?
Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.
Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?
Does c have circular shift operators?
What is assignment operator?
Explain what are run-time errors?
What are the different types of endless loops?
What is keyword in c?
Why is sprintf unsafe?