Number is prime or not

C program to check whether the number entered by the user is prime or not.

Prime number is a number that is greater than 1 and is divisible only by 1 or itself. In other words, prime numbers can't be divided by other numbers than itself or 1. The first few prime numbers are {2, 3, 5, 7, 11, 13, 17 ...}

A number that is not prime is a composite number. A composite number is a number that can be divided by more than two numbers.

1 is neither Prime nor composite because it can be divided only by itself.

Program

#include<stdio.h>
#include<conio.h>
void main()
{
	int num,i,flag=0;

	printf("Enter the number\t:");
	scanf("%d",&num);

	for(i=2;i<=num/2 ;i++)
	{
		if(num%i==0)
		{
			flag=1;
			break;
		}
	}

	if(flag==0)
		printf("Number is prime");
	else
		printf("Number is not prime, it is composite");

	getch();
}

Output

********** Run1 **********

Enter the number        :54
Number is not prime, it is composite
********** Run2 ********** Enter the number :11 Number is prime