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 |
What is calloc() function?
What is the proper way of these job Tell me about there full work
What is the difference between functions getch() and getche()?
what is the difference between <stdio.h> and "stdio.h"
14 Answers Invendis, Kanbay, Mastek, MathWorks,
who is first prime minister in india??
What is nested structure with example?
What are the differences between new and malloc in C?
Why is #define used?
How can I generate floating-point random numbers?
What is identifiers in c with examples?
What is the function of this pointer?
0 Answers Agilent, ZS Associates,
How can I change their mode to binary?