Home / Programs / Write a program for printing prime numbers between 1 and 100.
Programming Example

Write a program for printing prime numbers between 1 and 100.

👁 1,962 Views
💻 Practical Program
📘 Step by Step Learning

Write a program for printing prime numbers between 1 and 100.

Information & Algorithm

If you don't know what is prime number please read form this tutorial. Prime Number & Prime Factors

Program Code

#include <stdio.h>
#include <math.h>
int main()
{
	int i, j,r;
	for(i = 2; i <= 100; ++i)
	{
		r=1;
		for(j = 2; j <= sqrt(i); ++j)
		{
			r=i%j;
			if(r == 0)
				break;
		}
	if(r!=0)
		printf("%d\n", i);
	}

    getch();
	return 0;
}

Output

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

Explanation

None

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.