please correct this code i didnt get the mistake #include #define NROWS 8 #define NCOLS 8 #define TRUE 1 #define FALSE 0 void main(){ int queenht_row, queenht_col; int line,row,col,i,j; int filled; printf("Chess queenht Program\n"); do{ printf("Enter queenht's coordinates: "); scanf("%d %d",&queenht_row,&queenht_col); }while((queenht_row<1)||(queenht_row>NROWS)||(queenht_col<1)||(queenht_col>NCOLS)); for(line=1;line<=2*NROWS+1;line++){ row = line/2; if(line%2!=0){ printf("+"); for(col=1;col<=NCOLS;col++) printf("---+"); printf("\n"); } else{ printf("|"); for(col=1;col<=NCOLS;col++){ filled=FALSE; if((row==queenht_row) && (col==queenht_col)){ printf(" Q |"); filled = TRUE; continue; } for(i=-2;i<=2;i++){ for(j=-2;j<=2;j++){ if((i==j)||(i==-j)||(i==0)||(j==0)) continue; if((queenht_row+i==row)&&(queenht_col+j==col)){ printf(" |"); filled = TRUE; for (upperdiag = 0; upperdiag < queen_upperdiag; upperdiag++) { if (queen_upperdiag , lowerdiag) // there is already a queen in upper diagonal! filled = FALSE; } filled = TRUE; } } } if(!filled) printf(" |"); } printf("\n"); } } }
please correct this code i didnt get the mistake
#include<stdio.h>
#define NROWS 8
#define NCOLS 8
#define TRUE 1
#define FALSE 0
void main(){
int queenht_row, queenht_col;
int line,row,col,i,j;
int filled;
printf("Chess queenht
do{
printf("Enter queenht's coordinates: ");
scanf("%d %d",&queenht_row,&queenht_col);
}while((queenht_row<1)||(queenht_row>NROWS)||(queenht_col<1)||(queenht_col>NCOLS));
for(line=1;line<=2*NROWS+1;line++){
row = line/2;
if(line%2!=0){
printf("+");
for(col=1;col<=NCOLS;col++)
printf("---+");
printf("\n");
}
else{
printf("|");
for(col=1;col<=NCOLS;col++){
filled=FALSE;
if((row==queenht_row) && (col==queenht_col)){
printf(" Q |");
filled = TRUE;
continue;
}
for(i=-2;i<=2;i++){
for(j=-2;j<=2;j++){
if((i==j)||(i==-j)||(i==0)||(j==0))
continue;
if((queenht_row+i==row)&&(queenht_col+j==col)){
printf(" |");
filled = TRUE;
for (upperdiag = 0; upperdiag < queen_upperdiag; upperdiag++)
{
if (queen_upperdiag , lowerdiag) // there is already a queen in upper diagonal!
filled = FALSE;
}
filled = TRUE;
}
}
}
if(!filled)
printf(" |");
}
printf("\n");
}
}
}
Step by step
Solved in 4 steps with 3 images