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


Please Help Members By Posting Answers For Below Questions

Can you pass an entire structure to functions?

696


Tell me when is a void pointer used?

648


Given below are three different ways to print the character for ASCII code 88. Which is the correct way1) char c = 88; cout << c << " ";2) cout.put(88);3) cout << char(88) << " "; a) 1 b) 2 c) 3 d) constant

669


What is a header file?

638


Apart from dennis ritchie who the other person who contributed in design of c language.

813






how to make a scientific calculater ?

1565


what is a function method?give example?

1914


Combinations of fibanocci prime series

1114


Can we declare a function inside a function in c?

590


What are # preprocessor operator in c?

632


What are the valid places to have keyword “break”?

651


how to count no of words,characters,lines in a paragraph.

3907


How can you check to see whether a symbol is defined?

592


how do you execute a c program in unix.

636


4. main() { int c=- -2; printf("c=%d",c); }

1370