vendredi 24 janvier 2020

Continue statement in If Else condition gives infinite loop

I was solving a problem on strings and for that I came up with this solution.

#include <stdio.h>
#include <string.h>
int main() {
    //code
    int t,flag;
    scanf("%d", &t);
    while(t--){
        int n,i=0;
        scanf("%d", &n);
        char str[100];
        scanf("%s", str);

        while(i<n){
            if (str[i]!= str[n-1-i]){
             flag = 1;  
            printf("%d", flag);
            break;
            }
            else{
            flag = 0;
           printf("%d", flag);
            continue;
            }
            i++;
    }
    if(flag ==1 )
    printf("No\n");
    else
    printf("Yes\n");
    }   
    return 0;
}

This code works fine when continue is removed, but when the above code is run, it prints 0 infinitly. Can you help me where I'm going wrong?

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire