how to print this pyramid *
*
*
* * * * * * *
*
*
*

Answers were Sorted based on User's Feedback



how to print this pyramid * * ..

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

how to print this pyramid * * ..

Answer / 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

More C Interview Questions

What is calloc() function?

0 Answers  


What is the proper way of these job Tell me about there full work

0 Answers   EDS,


What is the difference between functions getch() and getche()?

0 Answers  


what is the difference between <stdio.h> and "stdio.h"

14 Answers   Invendis, Kanbay, Mastek, MathWorks,


who is first prime minister in india??

8 Answers   Wipro,


What is nested structure with example?

0 Answers  


What are the differences between new and malloc in C?

0 Answers   Amazon,


Why is #define used?

0 Answers  


How can I generate floating-point random numbers?

0 Answers  


What is identifiers in c with examples?

0 Answers  


What is the function of this pointer?

0 Answers   Agilent, ZS Associates,


How can I change their mode to binary?

0 Answers  


Categories