Skip to content
Home » C Programs » C Program to Print Prime Numbers From 1 to 100 Using For Loop

C Program to Print Prime Numbers From 1 to 100 Using For Loop

Simple c program to print prime numbers from 1 to 100 using for loop. Program to display prime numbers between two intervals using for loop and if else statement in a c programming language. 

For Loop in C

A for loop is a repetition control structure that lets you design a loop that needs to run a certain number of times quickly. 

In the C programming language, a for loop has the following syntax: The init step is done first and only once. 

Any loop control variables can be declared and initialised at this phase.

Flag Variable in C Program

In a software, flag is used as a signal. Its application is not confined to C programming; it may be used in any code, regardless of language. Its function is to regulate the program’s execution and, in some situations, to debug the program. 

A flag is a set of data bits that are used to record binary values as program structural indicators. A flag is a data structure element in a computer language. This is sample method to c program to print prime numbers from 1 to 100 using for loop.

C Program to Print Prime Numbers From 1 to 100 Using For Loop

#include<stdio.h>
int main() 
{
int minimum, maximum, i, flag;
printf("Enter two numbers");
scanf("%d %d", &minimum, &maximum);
printf("Prime Numbers %d and %d are", minimum, maximum);
while (minimum < maximum) 
{
flag = 0;
if (minimum <= 1) 
{
++minimum;
continue;
}
for (i = 2; i <= minimum / 2; ++i) 
{
if (minimum % i == 0) 
{
flag = 1;
break;
}
}
if (flag == 0)
printf("%d ", minimum);
++minimum;
}
}

Output:

Enter two numbers45
67
Prime numbers between 45 and 67 are47 53 59 61