What is reason for infinite loop in this c program?

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;
}

Thanks in Adavance!

@thepriyablog
The fifth line in your code has error. There is a syntax error in your “for loop”. There should be a semicolon after the condition i<one;
But you have comma after the condition.

2 Likes

Syntax error

1 Like

Well, there are some syntax error with your for loop, can you try below code to fix the error you are getting.

#include <stdio.h>

int main() {
    int one, two, three, sum = 0;

    // Prompt the user to enter a number
    printf("Enter a number: ");
    scanf("%d", &one);

    // Corrected the loop syntax
    for (int i = 1; i < one; i++) {
        // Resetting 'two' and 'three' at the beginning of each iteration
        two = 0;
        three = i;

        // Incorrect logic for accumulating sum
        sum = sum + two;

        // Incorrect placement of printf, should be outside the loop if you want to print the sum
        // Also, consider adding a newline character '\n' to make the output readable
        printf("%d ", sum);
    }

    // Corrected the placement of printf if you want to print the sum after the loop
    printf("\nTotal sum: %d\n", sum);

    return 0;
}

Thanks

replacw your comma with semi colon in your for loop and write the printf statment outside the paranthesis