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; }
Here is a simple program to generate prime numbers upto a given specific number /*Prime No. from 1 to 50*/ /*By-Himanshu Rathee*/ #include<stdio.h> #include<conio.h> void main() { int i,j,n; clrscr(); printf(" Enter the number upto which we have to find the prime number: "); scanf("%d",&n); printf("\n"); for(i=2;i<=n;i++) { for(j=2;j<=i-1;j++) if(i%j==0) break; /*Number is divisble by some other number. So break out*/ if(i==j) printf("\t%d",i); /*Number was divisible by itself (that is, i was same as j)*/ } /*Continue loop upto nth number*/ getch(); }
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
By learning how to program on C+.
This would require some computer knowledge. It can make it easier to find out the prime numbers without figuring it out in your head.
VBnet program to find the prime numbers between 100 to 200?
The first three prime numbers are 2,3 and 5.
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
The sum of the first 250 prime numbers is 182,109.
The sum of the first 25 prime numbers is 1,060.
the sum of the first 15 prime numbers is 328 .
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.
All prime numbers are odd, exept of the first prime number 2.