Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

This code just do not work,please tell me why?

+1 vote
asked Jan 4, 2023 by Milan Ognjenovic (130 points)
#include<stdio.h>

int main()
{
  int n,i,j;
  
  printf("How many rows you want in your pyramid?\n");
  
  scanf("%d",&n);
  
  for(i = 1; i <= n; i++)
     {
        for(j = 1; j >=2*n-1; j++)
        {
            if(j >= n-(i-1) && j <= n+(i-1))
            {
                printf("*");
                
            }
            else
            {
            printf(" ");
                
            }
       }
       printf("\n");
     }
     return 0;
       
}

2 Answers

+1 vote
answered Jan 4, 2023 by Peter Minarik (87,340 points)
for(j = 1; j <=2*n-1; j++)

Your code incorrectly checked if j >= 2 * n - 1, instead of the correct (above) less or equal state.

+1 vote
answered Jan 4, 2023 by beingPro007 (160 points)
try to put braces after 2*(n-1) like this
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...