C program to find prime number using for loop

C program to find prime number using for loop

What is prime number?

A number is considered as prime number when it satisfies the below conditions.

  • It should be whole number
  • It should be greated than 1
  • It should have only 2 factors. They are, 1 and the number itself.

Example for prime numbers: 2, 3, 5, 7, 11, 13, 17, 19, 23 etc.

Why 4, 6, 8, 9, 10, 12, 14, 15, 16 etc are not prime numbers?

Because, the number 4 can be factored as 2*2 and 1*4. As per the rule of prime number, there should be 2 factors only. They are 1 and the number itself. But, number 4 has 2*2 also. Like this, all remaining numbers 6, 8, 9, 10, 12, 14, 15, 16 have factors other than 1 and the number itself. So, these are not called as prime numbers.

#include <stdio.h>
int main()
{
int i, num, p = 0;
printf("Please enter a number: \n");
scanf("%d", &num);
for(i=1; i<=num; i++)
{
if(num%i==0)
{
p++;
}
}
if(p==2)
{
printf("Entered number is %d "\
"and it is a prime number.",num);
}
else
{
printf("Entered number is %d "\
"and it is not a prime number.",num);
}
}
OUTPUT:
Please enter a number: 13 
Entered number is 13 and it is a prime number.

Search Term

c program prime number
c program prime numbers from 1 to n
c program prime number 1 to 100
c program prime number using function
c program prime number using while loop
c program prime number between 1 100
c program prime number using recursion
c program prime number upto n
c program prime number using for loop
c program prime number array
c program prime number generation
c program prime number or not
c program prime number between 1 n
c program prime number algorithm
c program for prime number and composite
c program for prime number in a given range
c program prime factors of a number
c program about prime number
c program to find prime number in a given range
c program to find prime number in array
c program to find prime number within a range
c program to find prime number between a range
write a c program prime number
a c program to print prime numbers
a c program to display prime numbers
c program prime numbers from 1 to 100
write a c program for prime number series
c program for prime number between given range
c program for prime number between 1 to 100 using while loop
c program for prime number between 1 to 50
c program for prime number between 1 to 10
c program for prime number between 1 to 1000
c program for prime number between 1 to n using for loop
c program for prime number between 1 to 300
c program for prime number between 50 to 100
c program prime number check
c program for prime number using command line arguments
co prime number c program
c program for prime number using conditional operator
circular prime number program in c
c program to check prime number using function
c program to check prime number using while loop
c program to check prime number using for loop
c program to find prime number using command line arguments
c program prime numbers spelt with prime number of letters
c program for prime number using do while loop
c program determine prime number
c program to check prime number using do while loop
c program to display prime number between 1 to 100
c program to display prime number
c program to print prime number using do while loop
c program to find prime number using do while loop
c program to detect prime number
c program to display prime number between interval using function
c program to display nth prime number
c program for prime number with explanation
c program to check prime number with explanation
c program to find prime number using if else
c program to check prime number using if else
c program for prime number or not with explanation
efficient c program for prime number
simple c program for prime number with explanation
c program for prime number or not using if else
easy c program to find prime number
c program to find entered number is prime or not
c program prime factors number
c program to check prime number flowchart
c program to print prime number from 1 to 300
c program to print prime number from 1 to n
c program to print prime number from 1 to 50
c program to print prime number from 1 to 1000
c program to check prime number geeksforgeeks
c program to find prime number geeksforgeeks
c program to find prime number generation
c program to find prime number in given range
c program to generate prime number series
c program to get prime number
c program to print prime number between given range
c program to find prime number in a given range using while loop
c program for prime number in hindi
how to make c program for prime number
c program for prime number using if else
c program for prime number using if statement
c program for prime number in an array
c program for prime number in linux
c program to implement prime number
c program to find prime number between 1 and 100 java
c program prime number logic
c program for prime number list
c program to find prime number less than n
c program to find prime number less than 100
c program for prime number without loop
c program largest prime number
c program for prime number between m and n
c program to find prime number in a matrix
c program to check prime and armstrong number by making function
mersenne prime number c program
c program to find prime numbers between m and n
c program to print prime numbers between m and n
c program for prime number or not using while loop
c program for prime number or not using function
c program for prime number or not using for loop
c program for prime numbers below n
c program n prime numbers
c program to print n prime numbers using for loop
c program to generate n prime numbers using for loop
c program to print first n prime numbers using while loop
c program to print first n prime numbers using for loop
c program for sum of n prime numbers
c program to print prime number or not
c program to find prime number or not using for loop
c program to find prime number or not using recursion
c program to check prime number or not without using recursion
c program for prime number pdf
c program to find prime number pdf
c program prime number program
c program for prime number using pointer
c program print prime number
c program print prime number 1 to 100
c program print prime numbers upto n
c program to print prime number series
c program to print prime number pyramid
c program for prime number using recursive function
c program for prime number in range
c program to find prime number between range
c program to print prime number between range
c program to find prime number using square root
c program to find nth prime number using recursion
c program to find relative prime number
c program prime number series
c program in prime numbers
c program sum prime numbers
c program to find prime number using switch case
c program for super prime number
c program prime numbers 1 to n
c program prime number between 1 to 100
c program to prime number
c program twin prime number
c program to check prime number
c program for prime numbers less than n
c program to find prime number using function
c program to print prime number
c program for prime number using array
c program to verify prime number
prime number program in c video
c program for prime number within a range
c program for prime number without using loop
c program for prime number with flowchart
c program for prime number without using flag
c program for prime number with output
c program to find prime number without loop
prime number program in c youtube
c program for prime number upto 100
c program of prime number between 1 to 20
c program find prime number upto 100
c program prime numbers 1 to 100
c program for prime number between 1 to 10 using for loop
c program to print the prime number from 2 to n where n is given by user
c program to find prime number between 1 and 20
c program to print prime numbers from 2 to n
c program to find prime numbers from 2 to 100
c program to find prime numbers between 2 and 100
c program to print prime numbers from 2 to 100
c program to generate prime numbers between 2 to n
c program to print prime number between 1 to 300
c program to find prime number between 50 and 100
c program to find prime number upto 50
c program for first 50 prime number
c program to print first 50 prime number
c program to find prime number between 1 and 500
c program to print first 5 prime numbers
c program to find first 5 prime numbers

Related posts

Leave a Comment