+ 3

Help me with this code.

I don't know what's wrong with this. . . #include <stdio.h> int main() { int i,j,rows; printf("Enter number of rows ;"); scanf("%d,&rows"); for(i=1;i<=rows;i++){ for(j=i;j<rows;j++){ printf(" "); } for(j=1;j<=(2*i-1);j++){ if(i==rows || j==1 || j==(2*i-1)){ printf("*"); } else{ printf(" "); } } printf("\n"); } return 0; }

8th Feb 2025, 5:43 PM
𝓐𝓭𝓲𝓽𝓲⚝
𝓐𝓭𝓲𝓽𝓲⚝ - avatar
3 Answers
+ 5
𝓐𝓭𝓲𝓽𝓲⚝ I addressed a few issues with your code including adding a default value if no input https://sololearn.com/compiler-playground/cMncdK26b8MB/?ref=app https://sololearn.com/compiler-playground/cxaS0PaKV6f9/?ref=app
8th Feb 2025, 6:31 PM
BroFar
BroFar - avatar
+ 4
𝓐𝓭𝓲𝓽𝓲⚝ there is a minor syntax error in your code. In the scanf statement you need to give double quotes only for the %d and not the whole statement. Below is the correct one scanf("%d",&rows);
8th Feb 2025, 6:06 PM
Aysha