mercredi 15 avril 2020

The loop is not terminating and the program enters into the wrong conditional statement

This is my program:

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>



int main() 
{
    int a, b, i;
    scanf("%d\n%d", &a, &b);
    // Complete the code.
    for(i=a;i<=b;i++)
    {
        if (i=1)
        {
            printf("one");
        }
        else if(i=2)
        {
            printf("two");
        }
        else if(i=3)
        {
            printf("three");
        }
        .
        .
        .
        }
    }
    return 0;
}

it goes till 10. Even if a=8 the i=1 condition is executed and doesn't terminate. The output is oneoneoneoneoneoneoneoneone.....

Aucun commentaire:

Enregistrer un commentaire