
Check the input array for non-prime numbersįor (int i = 0 i < inputNumbers. First, find all the prime numbers from 1 to n
#COMPOSITE NUMBERS CODE#
This code is to illustrate the algorithm only) vector inputNumbers

So a pseudo C code for your problem would be (I haven't run this through compilers yet, so please ignore syntax errors. That's very inefficient.Īs other guys suggested, you need to do something like the Sieve of Eratosthenes.

Using n as the maximum value in the vector and the number of elements in the vector is confusing and pointless. Second, your output will contain duplicates as you're testing and outputting each input number every time it fails the (broken) divisibility test. First, you're testing i % v = 0, which is backwards and also explains why you get all numbers. They are placed in this: vector nĪnd the values are inserted like this: srand(1) A composite number is a positive integer that has at least one divisor other than 1 and. The range is actually determined by the user but it will be up to 1000 integers. Python program to check whether the given number is a composite number or not.
