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 is difference between structure and union in c?
Can you please compare array with pointer?
How is pointer initialized in c?
Is there any algorithm to search a string in link list in the minimum time?(please do not suggest the usual method of traversing the link list)
What is s or c?
What does int main () mean?
Which header file should you include if you are to develop a function which can accept variable number of arguments?
What are identifiers c?
Which function in C can be used to append a string to another string?
What is a macro, and explain how do you use it?
hi any body pls give me company name interview conduct "c" language only
What are formal parameters?
How do c compilers work?
If a five digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits.For example if the number that is input is 12391 then the output should be displayed as 23402
Is a house a mass structure?