OneCompiler

what is reason for infinite loop in this c program and what are the errors in it

#include <stdio.h>

int main() {
int one,two,three,sum=0;
printf("enter a number");

scanf("%d",&one); 
for(int i=1;i<one,i++;){
    
    two=0;
    three=i;
    
    
    sum= sum+two;
    
    two=three;
    printf("%d",sum);
    
    
}


return 0;

}

2 Answers

2 years ago by

if the loop continues to run,system memory will fill up.there will come a tie when our system memory will be fill up and code will not able to work futher.

2 years ago by Gaurav Chauhan

you probably want to use

   for(int i=1; i<out; i++) { 

but you write coma instead of semicolon after out

   for(int i=1; i<out,i++; ) { 

then
i<out,i++ is evaluated as i++
because i++ is last in coma separated list

condition where i > 0 is true
so i= 1, 2, 3, 4, 5 ... never causes end of loop

2 years ago by zemiak