Detection of a Prime Number

Write a program to determine whether a number is prime or not.
A prime number is one, which is divisible only by 1 or itself.



#include<stdio.h>
main()
{
int num, i;

printf ("Enter a number:");
scanf ("%d", &num);

i=2;
while (i<=num - 1)

{
if (num % i ==0)

{
printf ("Not a prime number");
break;
}

i++;
}

if (i == num)

printf ("Prime Number");
}



Comments

Popular posts from this blog

C Program - Calculation of Area and Circumference of a Circle using Pointers

Matchstick Game using C Programming

Generation of Fibonacci Sequence using Recursion.