jeudi 19 septembre 2019

How to fix counter in C

For some reason, when I try to count the number of times the if statement i==1001 C fails to do so. Instead, I get no value for the counter. Any idea what's happening?

int main()
{
    int height,width,i, counter=0;
    double x,y,grid=10,a,b,t;
    for(height=0;height<=2*grid;height++){

        b=1-(height/grid);

        for(width=0;width<=4*grid;width++){

            a=-2+(width/grid);
            x=0;
            y=0;
            for(i=1;i<=1000;i++){
                t=x;
                x=(x*x)-(y*y)+a;
                y=(2*t*y)+b;
                if((x*x)+(y*y)>2)
                    break;
            } 

            if(i==1001){
                printf(".");
                counter++;
            }

            else{
                printf(" ");
            }



        }
        printf("\n");

    }
    printf(counter);
    getch();
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire