Hey i am outta my wits to get the folowing output in C. Can ne1 help


O/p reqd:


*
* *
* * *
* * * *
* * * * *

and so on.


see th pyramid is not the desired one when you open this back and just move the mouse pointer on the post to find out the pyramid i wnt. thnks

This is one way of doing it (not so efficient). I am not quite familiar with printf. I believe using printf efficiently the two nested for loops can be removed. Refer some books in C for the usage of printf statement.

#include <stdio.h>
int main() {
 int i, k, n= 20;
  
 for (i=1;i<=n;i++)
 { 
  for(k = n-i; k>0;k--)
    printf(" ");
  for(k=1;k<2*i;k++)
   printf("%c",'*');
  printf("\n");
 }
 return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.