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.

what is the problem in this c code?

+4 votes
asked Jan 22, 2018 by PH. 1 flag
#include<stdio.h>

main()

{

int a,b,c,d;

printf("Enter the rows upto which U want to print triangle star pattern\n");

scanf("%d \n",&a);

b==a;

while(a>=0)

{

for(c=1;c<(a-1);c++)

{

printf(" ");

}

for(d=1;d<=(2*(b-a)+1);d++)

{

printf("*");

}

printf("\n");

a--;

}

return(0);

}

8 Answers

0 votes
answered Jan 23, 2018 by Kayan Anjum (140 points)
nothing ...
all code are right to print date
0 votes
answered Jan 24, 2018 by Robayet Al Hamim (310 points)

printf(" ");

you fucked up there :)

0 votes
answered Jan 26, 2018 by Al3x76 (180 points)
#include<stdio.h>

int main()

{

int a,b,c,d;

printf("Enter the rows upto which U want to print triangle star pattern\n");

scanf("%d \n",&a);

b=a;

while(a>=0)

{

for(c=1;c<(a-1);c++)

{

printf(" ");

}

for(d=1;d<=(2*(b-a)+1);d++)

{

printf("*");

}

printf("\n");

a--;

}

return(0);

}
0 votes
answered Jan 31, 2018 by vijaypanchal (150 points)
#include <stdio.h>

int main()

{

int a,b,c,d;

    printf("Enter the rows upto which U want to print triangle star pattern\n");

    scanf("%d",&a);

    for(d=1; d<=a; ++d, b=0)

    {

        for(c=1; c<=a-d; ++c)

        {

            printf("  ");

        }

        while(b != 2*d-1)

        {

            printf("* ");

            ++b;

        }

        printf("\n");

    }

    

    return 0;

}

Output:

Enter the rows upto which U want to print triangle star pattern
4
      *
    * * *
  * * * * *
* * * * * * *

.
commented Feb 2, 2018 by anonymous 1 flag
printf("* ");
change printf(" * "); like this
0 votes
answered Jun 5, 2018 by Nikhil Kakkireni (320 points)
here you used b==a

it is used in the compare case only

so here you should use just b=a
0 votes
answered Jun 5, 2018 by Saurabh (600 points)

ALTERNATE WAY TO DO THIS:-

#include<stdio.h>

int main()

{

int row;
printf("Enter the rows upto which U want to print triangle star pattern\n");
scanf("%d \n",&row);

int t1=row;

int t2=row;

for(int i=1;i<=row;i++)

{

for(int j=1;j<=row*2-1;j++)

{

if( j<t1 && j>t2)

{

printf(" ");

}

else

{

printf("*");

}

}

t1--;

t2++;

printf("\n");

}

return 0;

}

commented Jun 6, 2018 by Raja D (180 points)
no error kin this program
0 votes
answered Jun 6, 2018 by Raja D (180 points)
no error in this program,but if you enter the any number it will print only one star
0 votes
answered Nov 27, 2023 by nasiya (240 points)
Can you please add "int" before  main
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.
...