# C Program To Print Prime Numbers From 1 To 100

C program to print prime numbers from 1 to 100. If you are looking for C program to find prime numbers, here in this tutorial we will help you to learn how to write a C program for prime numbers.

## C Program to Print Prime Numbers

Learn how to write a C program to print all Prime numbers between 1 to 100. Writing a C program to display prime numbers between two intervals can be done using various techniques but here in this program, we show how to write a C program to print prime numbers from 1 to 100 in a proper way.

### C Program to Print Prime Numbers Source Code

```/* C Program to print prime numbers from 1 to 100 - PrimeNumbers.C */

#include <stdio.h>
#include <stdlib.h>

void main()
{
//variable declaration
int num1, num2, i, j, flag, temp, count = 0;

printf("Enter the value of num1 and num2 \n");
scanf("%d %d", &num1, &num2);
//logic to finding and printing prime numbers from 1 to 100
if (num2 < 2)
{
printf("There are no primes upto %d\n", num2);
exit(0);
}

printf("Prime numbers are \n");
temp = num1;

if ( num1 % 2 == 0)
{
num1++;
}

for (i = num1; i <= num2; i = i + 2)
{
flag = 0;
for (j = 2; j <= i / 2; j++)
{
if ((i % j) == 0)
{
flag = 1;
break;
}
}
if (flag == 0)
{
printf("%d\n", i);
count++;
}
}
printf("Number of primes between %d & %d = %d\n", temp, num2, count);
}```

### C Program to Print Prime Numbers Output

Enter the value of num1 and num2

1

100

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      97

Number of primes between 1 & 100 = 25