In this article, we will show you, How to write a C Program to Print Prime Numbers from 1 to 100 or Minimum to maximum, or prime Numbers within a specific range, and some of the prime numbers within a range using For Loop and While Loop.

**TIP:** We already explained the logic to check whether the given is prime or not in C Program to Find Prime Number article. I suggest you refer the same.

## C Program to Print Prime Numbers from 1 to 100 Using For Loop

This C program will print Prime Numbers between 1 to 100. Here, first For Loop will make sure that the number is between 1 and 100.

/* C Program to Print Prime Numbers from 1 to 100 using For Loop */ #include <stdio.h> int main() { int i, Number, count; printf(" Prime Number from 1 to 100 are: \n"); for(Number = 1; Number <= 100; Number++) { count = 0; for (i = 2; i <= Number/2; i++) { if(Number%i == 0) { count++; break; } } if(count == 0 && Number != 1 ) { printf(" %d ", Number); } } return 0; }

**OUTPUT**

## C Program to Print Prime Numbers from 1 to 100 Using While Loop

We just replaced the For loop in the above example with While loop. If you don’t understand the While Loop, please refer While Loop article here: WHILE LOOP

/* C Program to Print Prime Numbers from 1 to 100 using While Loop */ #include <stdio.h> int main() { int i, Number = 1, count; printf(" Prime Number from 1 to 100 are: \n"); while(Number <= 100) { count = 0; i = 2; while(i <= Number/2) { if(Number%i == 0) { count++; break; } i++; } if(count == 0 && Number != 1 ) { printf(" %d ", Number); } Number++; } return 0; }

**OUTPUT**

## C Program to Print Prime Numbers from 1 to N Using For Loop

Instead of printing prime numbers from 1 to 100, you can allow the user to decide the minimum and maximum values. This program allows the user to enter Minimum and Maximum values. Next, the program will print prime numbers between Minimum and Maximum values using For Loop.

/* C Program to Print Prime Numbers from 1 to n using For Loop */ #include <stdio.h> int main() { int i, Number, count, Minimum, Maximum; printf("\n Please Enter the Minimum & Maximum Values\n"); scanf("%d %d", &Minimum, &Maximum); printf("Prime Numbers Between %d and %d are:\n", Minimum, Maximum); for(Number = Minimum; Number <= Maximum; Number++) { count = 0; for (i = 2; i <= Number/2; i++) { if(Number%i == 0) { count++; break; } } if(count == 0 && Number != 1 ) { printf(" %d ", Number); } } return 0; }

**OUTPUT**

## C Program to Print Prime Numbers from 1 to N Using While Loop

This program is same as above but we replaced the For loop with While Loop.

/* C Program to Print Prime Numbers from 1 to N using While Loop */ #include <stdio.h> int main() { int i, Number, count, Minimum, Maximum; printf("\n Please Enter the Minimum & Maximum Values\n"); scanf("%d %d", &Minimum, &Maximum); Number = Minimum; printf("Prime Numbers Between %d and %d are:\n", Minimum, Maximum); while(Number <= Maximum) { count = 0; i = 2; while(i <= Number/2) { if(Number%i == 0) { count++; break; } i++; } if(count == 0 && Number != 1 ) { printf(" %d ", Number); } Number++; } return 0; }

**OUTPUT**

## C Program to find Sum of Prime Numbers from 1 to 100

This program finds the prime numbers between 1 and 100. Next, it is going to add those number to find the sum of all prime numbers between 1 and 100.

/* C Program to find Sum of Prime Numbers Between 1 to 100 */ #include <stdio.h> int main() { int i, Number, count, Sum = 0; for(Number = 1; Number <= 100; Number++) { count = 0; for (i = 2; i <= Number/2; i++) { if(Number%i == 0) { count++; break; } } if(count == 0 && Number != 1 ) { Sum = Sum + Number; } } printf(" Sum of Prime Numbers between 1 to 100 = %d", Sum); return 0; }

**OUTPUT**

## C Program to find Sum of Prime Numbers from 1 to N

Instead of adding prime numbers from 1 to 100, you can allow the user to decide the minimum and maximum values. This program allows the user to enter Minimum and Maximum values. Next, it will find the sum of prime numbers between Minimum and Maximum values using For Loop.

/* C Program to Print Sum of Prime Numbers from 1 to 100 */ #include <stdio.h> int main() { int i, Number, count, Sum = 0, Minimum, Maximum; printf("\n Please Enter the Minimum & Maximum Values\n"); scanf("%d %d", &Minimum, &Maximum); for(Number = Minimum; Number <= Maximum; Number++) { count = 0; for (i = 2; i <= Number/2; i++) { if(Number%i == 0) { count++; break; } } if(count == 0 && Number != 1 ) { Sum = Sum + Number; } } printf(" Sum of Prime Numbers between %d and %d = %d", Minimum, Maximum, Sum); return 0; }

**OUTPUT**

Thank you for Visiting Our Blog