Question

Part 3: Call your program by the name: "program_003_store_first_1000_primes_in_an_ARRAY". This program must create an array of...

Part 3: Call your program by the name: "program_003_store_first_1000_primes_in_an_ARRAY".

This program must create an array of integers, of size 1000. Then, it must store the first 1000 prime numbers in the array. Then, it must print out the contents of the array.

C Programming Language

Homework Answers

Answer #1

Below is the c program to get first 1000 prime numbers abd those prime numbers to array and print out the umbers from array.

#include <stdio.h>

int main()
{
    int n = 1000, i = 2, count, c, j=0;
    int primeArray[1000];
    
    for(count = 1; count <= n; i++)  
    {
        // check c is prime or not
        for(c = 2; c < i; c++)
        {
            if(i%c == 0)
                break;
        }

        if(c == i)  // c is prime
        {
            //add prime number to array
            primeArray[j]=i;
            count++;    // increment the count of prime numbers
            j++;
        }

    }
    
    for(int k=0; k<1000; k++)
     {
         //Print the array element
         printf(" %d ", primeArray[k]);
     }
    
    return 0;
}

Below is the output screenshot

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Class work # 12 / Chapter 6 –> Arrays 3 (two dimensional arrays) Part 1: Create...
Class work # 12 / Chapter 6 –> Arrays 3 (two dimensional arrays) Part 1: Create a 2-by-3 integer array and initialize it with 6 integers of your choice. Using nested for loops, display the contents of the array on the screen Part 2: (Continue on part 1) Display the sum of all the integers in the array that you created in part 1. Create a function Part 3: Create a function that will display the elements of the array...
Write a program with the below specifications/requirements: (Java Language) -Create two arrays of size 10 to...
Write a program with the below specifications/requirements: (Java Language) -Create two arrays of size 10 to hold integers - Initialize the two arrays with random numbers in the range {0,19} -Print the contents of the two arrays after initialization -Print the numbers that exist in both arrays( i.e intersection of arrays)
Write a program in Java that creates an array of doubles. The array must have size...
Write a program in Java that creates an array of doubles. The array must have size 1000. Fill this array with random numbers between 0 and 1. Then compute and print the total value of all the elements of the array, the mean, the minimum, and the maximum. Filling the array with random numbers must be done by a method that you define and implement. Computing and printing the statistics must be done by another method, which again you must...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using the following guidelines - Write two primary helper functions - one iterative (IsArrayPrimeIter) and one recursive (IsArrayPrimeRecur) - each of which Take the array and its size as input params and return a bool. Print out a message "Entering <function_name>" as the first statement of each function. Perform the code to test whether every element of the array is a Prime number. Print out...
Write a method name maxElement, which returns the largest value in an array that is passed...
Write a method name maxElement, which returns the largest value in an array that is passed as an argument. The method must use recursion to find the largest element. Demonstrate the method in a program. Write the JAVA CODE on the paper that is provided. (Put your name on every piece of paper) Use the following array to test the method. Int [] numbers = {2,12,1999,99,100,4,7,300} PROGRAMMING LANGUAGE- JAVA. Please answer the question ASAP. Thanks in advance!
Use C++ 1 a)Write a console program which creates an array of size 100 integers. Then...
Use C++ 1 a)Write a console program which creates an array of size 100 integers. Then use Fibonacci function Fib(n) to fill up the array with Fib(n) for n = 3 to n = 103: So this means the array looks like: { Fib(3), Fib(4), Fib(5), ...., Fib[102) }. For this part of assignment you should first write a recursive Fib(n) funcion, as was done in class.For testing, print out the 100 integers. 1 b) For second part of this...
In c++ Write a program that creates a dynamically allocated array to store students’ grades. The...
In c++ Write a program that creates a dynamically allocated array to store students’ grades. The user should be able to decide the size of the array during run time. Write code to fill this array from the keyboard and then print out the values of your array,
PYTHON 3 Write a program that prints the count of all prime numbers between A and...
PYTHON 3 Write a program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = 21212 B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7, 11, 13, 17, 19, 23, and 29. Rules: You should first...
Write a C program Design a program that uses an array to store 10 randomly generated...
Write a C program Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...
C++ 1. An array of integers is said to be a palindrome if it is read...
C++ 1. An array of integers is said to be a palindrome if it is read the same from right to left and from left to right such as 1 2 3 2 1. Implement a program that: a. Prompts the user for an integer value n which represents the number of integers to be read next. b. Create a one dimensional dynamic array with size equal to n. c. Create two pointers front and rear and make them point...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT