Prime Number Program in C | C Language Tutorial | Mr. Srinivas

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi everyone welcome to nourish technologies this is Seamus so in this session we are going to discuss so how to check whether the input number is a prime number or not using C programming here the program is a prime number or not is checking so first of all so what is a prime number what is a prime number means the number which is having two factors number number which is having two factors is called a prime number so here so I writing the program so first we need to read the n value so nothing but we need to read one number and how many factors are present to that number we need to check right for example if you take in value suppose seven seven and from one two so one two seven one two seven how many factors are there we need to check one is a factor or not two is a factor or not and so on it itself also 7 is a factor or not how to repeat this one two seven means what with the help of one loop suppose I value if you found any factor suppose if one is a factor so then the take one count variable if you find any factor to this variable n just increase the count value two is not the factor three is not the factor and so on again seven is the factor so here it is again increase the count value is two is to the finally check if count value is equals to two it is a prime number right if it is a less than two or greater than two it is not a prime number it is a simple logic right so here it is the number which is having two factors so how to write the program C so directly here it is I have started from the main function I want to read n value so I am declaring the variable and here it is we are asking printf printf enter n value they will input that one we are reading using scanners we are reading that integers into variable n L so next we need to repeat the loop so here it is I value we should start from 1 2 1 2 itself nothing but up to N so with the help of variable I we are repeating the loop I value starts from 1 to N so every time we are increasing by 1 and every time we are checking every time we are checking if n value n mod I the means what if I the n is divisible by I so we can say that I is a factor of M next row 2 is divisible or not 3 is divisible or not is nothing but every time we are checking if n is divisible by I here values of 7 I value varies 1 2 3 4 5 6 7 right if it is divisible so when means what how can you confirm that so whenever the remainder is 0 it is a divisible so here inside this we are increasing the count value count plus plus is a logic this for loop executes it depends on the N value suppose n value 7 7 times it will repeat and 7 times it will check the condition if this condition satisfies how many times the condition satisfies those many times the count value increases what is that initial value of count is a 0 count value is 0 okay and next one here if you form if the count value count value equals to 2 so directly we can print it's a prime number else not a prime number not prime number so this is the program that how to check whether the number is a prime number or not using C language syntax okay thank you all for more videos please subscribe to nourish 80 channel thank you [Music]
Info
Channel: Naresh i Technologies
Views: 715,289
Rating: 4.8634701 out of 5
Keywords: Prime Number Program in C, Prime Number Program, Prime Number, Numbers, Number Program in C, C Language Tutorial, C Language, C Programming, Srinivas, Naresh IT, C programming video tutorial, prime numbers in c, print prime numbers in c, add two numbers in c, prime number using c
Id: SKh_sXkPvVE
Channel Id: undefined
Length: 4min 46sec (286 seconds)
Published: Wed Apr 12 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.