+ 2
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; }
3 Antworten
+ 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
+ 3
𝓐𝓭𝓲𝓽𝓲⚝ 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);