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

Read N characters in to an array . Use functions to do all problems and pass the address of array to function. 1. Print only the alphabets . If in upper case print in lower case vice versa.

1 Answers  


#include<stdio.h> int main(){ int i=10; int *ptr=&i; *ptr=(int *)20; printf("%d",i); return 0; } Output: 20 can anyone explain how came the output is 20

0 Answers  


How do I swap bytes?

0 Answers  


5. What kind of sorting is this: SORT (k,n) 1.[Loop on I Index] repeat thru step2 for i=1,2,........n-1 2.[For each pass,get small value] min=i; repeat for j=i+1 to N do { if K[j]<k[min] min=j; } temp=K[i];K[i]=K[min];K[min]=temp; 3.[Sorted Values will be returned] A)Bubble Sort B)Quick Sort C)Selection Sort D)Merge Sort

2 Answers   Accenture,


What are linked lists in c?

0 Answers  






How can we open a file in Binary mode and Text mode?what is the difference?

1 Answers   PanTerra,


What is indirection in c?

0 Answers  


what is C?

9 Answers   Syntel,


struct abc { unsigned int a; char b; float r; }; struct xyz { int u; struct abc tt; }ww; ww = (struct xyz*)malloc(sizeof(struct xyz)); will the memory be allocated for the inner structure also?

1 Answers   Wipro,


Explain high-order and low-order bytes.

0 Answers  


How to print "Hi World" without using semi colon?

6 Answers   Infosys,


What is c definition?

0 Answers  


Categories