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 |
Explain how can you tell whether a program was compiled using c versus c++?
what is the code to display color fonts in the output?
array of pointer pointer to array pointer to pointer
How many keywords are there in c?
Subtract Two Number Without Using Subtraction Operator
What is the difference between array and linked list in c?
Is return a keyword in c?
Does c have an equivalent to pascals with statement?
What is the right type to use for boolean values in c? Is there a standard type? Should I use #defines or enums for the true and false values?
Is a pointer a kind of array?
What is difference between the following 2 lines…. int temp = (int)(0x00); int temp = (0x00int);
Explain why can’t constant values be used to define an array’s initial size?