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 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;
}

                        

🖥 Program 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
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.