 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can print prime numbers which are available between 1 to N with the help of C program. Before starting, you can note my information, you can follow or subscribe my YouTube channel through the URL youtube.com slash sanjaygupta underscore tech school. You can download my programming app Techimus which is available on Google Play. Now I am going to implement a code in front of you which will print all those prime numbers which are available between 1 to N. Some part of the program is already implemented in front of you. Here various variables are declared. Then printf will display this message enter value of N on console. Then the number will be received inside N using scanf. So this N will decide till that number you have to print those numbers which are prime. So starting from 1 to this N, we have to check all the numbers whether it is prime or not. So I have started a loop from 1 and it will repeat N times. Every time when this loop will be repeating, value of 5 will be provided into M variable. Then another variable f is initialized with 0. Now for checking whether M is prime or not, I have to use this loop J equals to 0, J less than M, J plus plus. Inside this loop, I am going to divide M by J. If the remainder is 0, it means number is not prime. So I am assigning 1 into f and I am breaking the loop. So after completion of this for loop which is controlled by J, I have to check the value of f. So if f remains 0, that means number is prime, otherwise it is not prime. So if this condition is true, then only I have to print the value on console which is available inside M variable. So I am writing here percent D is prime and I have printed value of M here. So this is the complete implementation of the program. You can see I just read value of N first, then a loop which is outer loop is repeating from 1 to N. Here I is assigning to M every time. Then f is flag variable which is initially 0. So this J loop is first checking whether M which is containing value of I is divisible by J or not. So if it is divisible by J, then value of f will become 1 and loop will be terminated using break keyword. If f is containing 1, then number is not prime. And if after completion of this loop, f remains 0, then only number is prime. So you can check the if condition which is implemented after completion of J loop. It is checking value of f whether it is 0 or 1. So if it is 0, then only value which is stored inside M will be displayed as prime. So this way you can print all the prime numbers which are available between the range of 1 to N. Now I am going to execute this code. You can see it is asking for the value of N. I am entering 100. Sorry, again I am executing this code. By mistake I started this J loop from 0. I have to start it from 2. That's why that error was a ring. Now you can see correct result is displayed. It is showing all the prime numbers between 1 to 100 because I have entered N as 100. So 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 and so on. All these numbers are prime which are available between 1 to 100. If you again execute this code and if you enter 200, you can see the remaining prime numbers are also displayed. So this time starting from 1 to 200, all prime numbers are displayed. So friends, I hope you have understood how you can print all prime numbers which are available between 1 to N. So this inner loop is checking for prime number and outer loop is controlling or you can say providing a particular number that we have to check whether it is prime or not. So with the help of combination of this master loop, we can check all the prime numbers which are available between a series. If you want to watch more programming related videos, you can follow or subscribe my YouTube channel that is youtube.com slash sanjaygupta underscore tax school. You can also download my programming app, Tachymus which is available on Google Play. So keep connected with me and watch programming related videos. Thank you for watching this video.