To output decimals

Asked 2 years ago, Updated 2 years ago, 138 views

int main(void)
{
    int num = 0;
    int* a = NULL;


    printf(">Positive Input : ");
    scanf("%d", &num);
    a = (int*)malloc(num-2);


    search(a,num);

    for (int i = 0; i < num-2; i++)
    {
        if(a[i-2] == 0) printf("X    ");
        else printf("%d", a[i-2]);
        if (i+1 % 5 == 0) printf("\n");
    }

}

void search(int*a ,int num)
{

    for (int i = 2; i < num; i++)
    {
        for (int j = 2; j < i; j++)
        {
            if (i % j == 0)
            {
                a[i - 2] = 0;
                break;
            }

        }
        if (a[i-2] != 0)
            a[i - 2] = i;
    }
}

I wanted to input a value in num and output it as minority value and X (non-minority value) from num-1 to num-1. It cannot be opened every 5th time and the desired output does not come out.

dynamic-allocation pointer c

2022-09-21 10:23

1 Answers

% is also a division operation, so it has a higher priority than plus.


2022-09-21 10:23

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.