how to print this pyramid *
*
*
* * * * * * *
*
*
*
Answers were Sorted based on User's Feedback
Answer / j.n.abhishek
void main()
{
int n,i,j;
clrscr();
printf("ENTER THE LIMIT:");
scanf("%d",&n);
for(i=0;i<=(2*n);i++)
{
if(i!=n)
{
for(j=0;j<(2*n);j++)
{
printf(" ");
}
printf("+\n");
}
else
{
for(j=0;j<=(2*n);j++)
{
printf("+ ");
}
printf("\n");
}
}
getch();
}
| Is This Answer Correct ? | 3 Yes | 1 No |
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 |
How to implement a packet in C
wt is diference between int and int pointer as same as float and float pointer and char and char pointer
What is the use of volatile?
Explain how can I manipulate strings of multibyte characters?
Write a program of prime number using recursion.
What does the message "automatic aggregate intialization is an ansi feature" mean?
Why we write conio h in c?
How can we see the Expanded source code and compiled code for our source program in C?
What is the meaning of this decleration? unsigned char (*pArray[10][10]); please reply.
what's the o/p int main(int n, char *argv[]) { char *s= *++argv; puts(s); exit(0); }
Write a program to reverse a string.
0 Answers Global Logic, iNautix, TCS, Wipro,
What do you mean by recursion in c?