jeudi 2 avril 2020

Why is this float array not printed properly?

I've tested various ways to fix this error and couldn't find a solution. Added a comment where It is supposed to be finding out all numbers who are outside of the (4.6, 9.7) loop. Could there be a mistake in the syntax?

int main()
{
    int i,n;

    float pom=0;
    printf("vnesi broj na elementi na nizata\n");

    scanf("%d",&n);
        float arr1[n], arr2[n];
    printf("vnesi elementi \n");
    for(i=0;i<n;i++)
    {
        scanf("%f",&arr1[i]);

    }

    pom =((arr1[0]+arr1[n-1])/2);

    int k = 0;

    for(i=0;i<n;i++)
    {

        if(arr1[i]<=4.6 && arr1[i]>=9.7) // the problem lies here
        {
            arr2[k]=arr1[i];
            k++;
            printf("%f", arr1[i]);
        }
    }

    printf("\n elementi od prva niza: \n");
    for(i=0; i<n; i++)
    {
        printf("%.2f ", arr1[i]);
    }

    printf("\n\n elementi od vtora niza: \n");


    for(i=0; i<k; i++)
    {
        printf("%f", arr2[i]); // is not printing the array

    }

}

Aucun commentaire:

Enregistrer un commentaire