how to print this pyramid *
*
*
* * * * * * *
*
*
*
Answer Posted / senthil
more generic answer considering for any value n (odd or even)
void printPlus(int n)
{
int i, j;
for(i=0; i<=n; i++)
{
if(i == n/2)
{
for(j=0; j<n; j++)
{
printf("* ");
}
printf("\n");
// to ignore last step of drawing for odd cnt
if(n%2 != 0)
{
i++;
}
}
else
{
for(j=0; j<n/2; j++)
{
printf(" ");
}
if(n%2 == 0)
{
// even
printf("\b*\n");
}
else
{
// odd
printf("*\n");
}
}
}
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Why do we use c for the speed of light?
Difference between Function to pointer and pointer to function
What is the difference between the local variable and global variable in c?
Explain what is wrong in this statement?
the statement while(i) puts the entire logic in loop. this loop is called a) indefinite loop b) definite loop c) loop syntax wrong d) none of the above
Why is C language being considered a middle level language?
#include
What is malloc calloc and realloc in c?
Differentiate call by value and call by reference?
Why doesn't C support function overloading?
What are high level languages like C and FORTRAN also known as?
Explain the binary height balanced tree?
Why c is called a middle level language?
What is masking?
What is sizeof int in c?