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
What will the preprocessor do for a program?
a way in which a pointer stores the address of a pointer which stores the value of the target value a) reference b) allocation c) multiple indirection d) none
What is the right way to use errno?
What is a char c?
Write a program to print numbers from 1 to 100 without using loop in c?
Describe wild pointers in c?
What is variable and explain rules to declare variable in c?
What is #include stdio h?
Can you write a programmer for FACTORIAL using recursion?
Input is "rama loves rajesh and rajesh Loves rama also and rajesh wear gloves and bloves" To print output is count the numbers of times repeted the word love without case sensitive.
Why main function is special give two reasons?
Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?
How do we declare variables in c?
What is cohesion in c?
What is the purpose of sprintf?