Computer Science, asked by jovinajoshi, 9 months ago

to print prime numbers between 1 and 100

Answers

Answered by arushimishra029
1

Answer:

The Prime number can be divisable by 1 and the number itself. If a number has more positive divisors other than 1 and the number itself, then the number is not Prime number. For example: 2, 3, 5, 7, 11, 13, 17 . . . are Prime numbers. The below given C program to display (print) the prime numbers between 1 and 100

Answered by AskewTronics
1

Python program :

Explanation:

prime=[]#take a list which holds the prime number.

for x in range(2,101):#for loop which runs from 2 to 100.

   c=0

   for y in prime:#loop which check for the prime number.

       if(x%y==0):#if condition which check the prime number.

           c=1

           break

   if(c==0):

       prime.append(x)

print(prime)

Output:

  • The above code will print the output as "[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]".

Code Explanation:

  • The above code is written in the python language, in which there is a one list name python which is used to hold the prime number.
  • There is a two for loop, first will runs to acess the number 2 to 100, because 1 is not a prime number.
  • The second loop is used to check the number to be prime or not, to do this it uses the smallest prime number which is saved in the list.

Learn More:

  • Python : https://brainly.in/question/14689905
Similar questions