fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int n;
  5. printf("Enter the number of rows: \n");
  6. scanf("%d",&n);
  7.  
  8. int nst=1;
  9. int nsp=n/2;
  10. int ml=n/2+1;
  11.  
  12. for(int i=1;i<=n;i++){
  13.  
  14. for(int j=1;j<=nsp;j++){
  15. printf(" ");
  16. }
  17.  
  18. for(int k=1;k<=nst;k++){
  19. printf(" * ");
  20. }
  21.  
  22. if(i<ml){
  23. nst+=2;
  24. nsp--;
  25. }
  26.  
  27. else{
  28. nst-=2;
  29. nsp++;
  30. }
  31.  
  32. printf("\n");
  33.  
  34. }
  35.  
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 5316KB
stdin
5
stdout
Enter the number of rows: 
       * 
    *  *  * 
 *  *  *  *  * 
    *  *  * 
       *