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
Can you pass an entire structure to functions?
Tell me when is a void pointer used?
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
What is a header file?
Apart from dennis ritchie who the other person who contributed in design of c language.
how to make a scientific calculater ?
what is a function method?give example?
Combinations of fibanocci prime series
Can we declare a function inside a function in c?
What are # preprocessor operator in c?
What are the valid places to have keyword “break”?
how to count no of words,characters,lines in a paragraph.
How can you check to see whether a symbol is defined?
how do you execute a c program in unix.
4. main() { int c=- -2; printf("c=%d",c); }