What is Prime number?
Prime number is a positive integer greater than 1 that is only divisible by 1 and itself. For example: 2, 3 , 5, 7, 11 are the first five prime numbers.
Logic to print prime numbers between 1 to n
Step by step descriptive logic to print all prime numbers between 1 to n.
- Input upper limit to print prime numbers from user. Store it in some variable say end.
- Run a loop from 2 to end, increment 1 in each iteration. The loop structure should be like
for(i=2; i<=end; i++)
. - Inside the loop for each iteration print value of i if it is prime number
Comments
Post a Comment