One way to do this is to write a function that checks if a number is prime:
def isPrime(number):
for i in range(2, number):
if number%i == 0:
return False
return True
Then create variables to track how many primes have been found and a variable to track which number is being tested for being prime. Increment that variable and test it, and if it is prime print it out (or save it somewhere) and increment the variable being used to track how many primes have been found:
targetPrimes = 10 #number of primes to find
primesFound = 0 #number of primes found
i = 1
while (primesFound < targetPrimes):
i += 1 #first number tested is 2
if isPrime(i):
print(i)
primesFound += 1
PRINT 2,3,5,7,11,13,17,19,23,29,31,37
This is the program that I couldn't fit in the question: Sorry for the underscores but it wouldn't let me indent# !/usr/bin/python# Filename: prime5.py#y = int(input('How many prime numbers do you want to see?'))x = 6w = 0primes = [2,3,5]z = len(primes)j = 0while w != 1:____if y*0!=0:________y = input('Please pick another NUMBER: ')____elif y*0==0:________w = w + 1while z
int sum = 0; int i; for(i = 0; i < n; ++i) { sum += i; }
If you just want a hint: One way to check whether a number is prime is by dividing it by any number between 2 and the square root of your number. If the number divides by any of these, it is not prime. If you want the code: import math for num in range(1,101): if all(num%i!=0 for i in range(2,int(math.sqrt(num))+1)): print num
Dunno about Linux, but I've written mine in C.It prime factorises the numbers, making a note of the highest power of each prime factor as it goes (in a linked list of malloc()ed structures). Once all the numbers have been factorised, it has a list of all the primes used along with their highest power. The lcm is then the product of the primes raised to their highest power.You are also not limited to the lcm of 2 numbers - you can keep factorising numbers until you run out of them and find the lcm of them all!Whilst you're at it you can add finding their hcf very easily: this time it's the product of the common primes to their lowest power.All that is then needed is the prime factorisation of the numbers.The normal method is:try the first prime (2)If it does not divide the number: set the prime to the next primeTry again from step 2Add one to the power count of this primereplace the number by the number divided by the primeif the number is not 1 go back to step 2Found all primes, stop!Finding the primes by which to divide is not easy on the fly, so you could check 2 specifically and then all odd numbers 3, 5, 7,..., but an improvement is to specifically check 2 and 3 and then check the numbers 6n ± 1 (which may be prime and why are 6n, 6n ± 2 and 6n ± 3 definitely not prime?) which skips every third odd number - this sequence of potential primes (5, 7, 11, 13, 17, 19, ...) can be easily generated.And while you're at it, you could display the prime factorisation you've done.And using that prime factorisation you can list the factors (and factor pairs) for the numbers.Obviously you'll need to sort out how the numbers are input to the program - I decode argv[], but you could use reading from stdin if you prefer.
By learning how to program on C+.
VBnet program to find the prime numbers between 100 to 200?
This would require some computer knowledge. It can make it easier to find out the prime numbers without figuring it out in your head.
Prime numbers are numbers that are only divisible by themselves and the number 1. You can write a program to print all prime numbers from 1 to 100 in FoxPro.
The first three prime numbers are 2,3 and 5.
the sum of the first 15 prime numbers is 328 .
The sum of the first 25 prime numbers is 1,060.
The sum of the first 250 prime numbers is 182,109.
The first 26 prime numbers are :- 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97and 101
fdsgfhgdfhgdf
The sum of the first five prime numbers is 28. The sum of the cubes of the first three prime numbers is 160. The average of 28 and 160 is 94.
Since there is an infinite set of prime numbers the answer would be infinity.