0

Can somebody help me why is this infinity loop in C?

I am actually solving a beginner questions from CodeForce(compitative programming) Question link: https://codeforces.com/problemset/problem/510/A But below code outputs infinity loop. My code: #include <stdio.h> #include <stdlib.h> int main() { int n=5,m=3;//row,column char board[n][m]; int i,j,side=0;//side is for in which side the hash(#) will be placed on the board int dotIndex;//dotIndex is positional value on a board where the dot(.) will be placed for(i=0;i<n;i+2) { for(j=0;j<m;j++) { board[i][j]='#'; printf("\ni = %d j = %d",i,j); } printf("\nStep 2"); if(side%2==0) { board[i+1][m-1]='#'; for(dotIndex=0;dotIndex<m-2;dotIndex++) board[i+1][dotIndex]='.'; } else{ board[i+1][0]='#'; for(dotIndex=1;dotIndex<m-1;dotIndex++) board[i+1][dotIndex]='.'; } printf("\nStep 4"); side++; } //Display board printf("\n"); for(i=0;i<n;i++) { for(j=0;j<m;j++) { printf(" %c",board[i][j]); } printf("\n"); } return 0; }

23rd May 2021, 9:37 AM
Sandesh Adhikari
Sandesh Adhikari - avatar
6 Antworten
+ 3
It is a infinet loop because of line fifteen for(i=0;i<n;i+2) You forgot the equal sign it should be for(i=0;i<n;i+=2)
23rd May 2021, 10:57 AM
Brain & Bones
Brain & Bones - avatar
+ 2
Caleb in fact, that's the equal sign wich was forgotten by OP, not the plus ;P
23rd May 2021, 3:43 PM
visph
visph - avatar
+ 2
Sandesh Adhikari OP = Original Poster
24th May 2021, 8:18 AM
visph
visph - avatar
+ 1
visph whoops, thanks 😁
23rd May 2021, 3:44 PM
Brain & Bones
Brain & Bones - avatar
0
visph OP means 🤔
24th May 2021, 8:17 AM
Sandesh Adhikari
Sandesh Adhikari - avatar
0
Caleb thanks
24th May 2021, 8:17 AM
Sandesh Adhikari
Sandesh Adhikari - avatar