c Modification of decimal output program using language array

Asked 2 years ago, Updated 2 years ago, 38 views

Using the code below, we're going to go from 1 to 100,000 Find the decimal number and the last one Five numbers 99929, 99961, 99971, 99989, 99991 I'd like to print something out.

"Code"

void demo_array_3() {

int big_boolean_array[100000];
int num_elements = sizeof(big_boolean_array) / sizeof(big_boolean_array[0]);

for (int i = 0; i < num_elements; i++) {
    big_boolean_array[i] = TRUE;
}
printf("big_boolean_array initialized.\n");

}

int main(void) {

demo_array_3();

return 0;

}

"Code"

c array

2022-09-21 18:07

2 Answers

#include <stdio.h>

int main(void)
{
    int i, j, count = 0;
    int numb[100001] = { 0 };
    for (i = 2; i <= 100000; i++)
    {   
        if (numb[i] == 0)
        {
            for (j = 2; i * j <= 100000; j++)
                numb[i*j] = 1;
        }
    }

    for (i = 100000; i >= 2; i--)
    {
        if (numb[i] == 0)
        {
            printf("%d\n", i);
            count++;
            if (count == 5)
                break;
        }
    }

    return 0;
}

Search for Eratosthenes' s sieve. You don't need to initialize an array. Just think of it as (index of array i) == (integer n). The array value of the decimal index is stored as 0. So you just have to pull out five indexes that have zero values in the array, going down by 1 from 100,000.


2022-09-21 18:07

for (int i=0; i<num_elements;i++) if(is_prime_number(i+1)==true) big_boolean_array[i]=false;

int counts=0;

for(i=num_element;i>=0,counts<5;i--) if(big_boolean_array[i]==false) {print (i) count++;}


2022-09-21 18:07

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.