This simple C program prints all the prime numbers between 1 and 100. A Prime number is a natural number greater than 1 that is only divisible by either 1 or itself. All numbers other than prime numbers are known as composite numbers. There are infinitely many prime numbers, here is the list of first few prime numbers
2 3 5 7 11 13 17 19 23 29 31 37....
This C program illustrates the use of nested for loops. The outer for loop iterate from 2 to 100 while the inner loop check the number for prime condition.
C Program to Print All Prime Numbers between 1 and 100 - Source code
Program Output
Program Explanation
1. This C program uses nested for loops to find and print all the prime numbers between 1 and 100.
2. The outer loop iterate through 2 to 100, while the inner loop use the modulus operator to check whether the number in current iteration is prime or not. If a prime number is found, the variable flag is set to 1 and the inner loop is existed using the break statement.
3. Otherwise, if flag variable remains zero, the number in current iteration is displayed on the screen as prime number.
need an explanation for this answer? contact us directly to get an explanation for this answer