Skip to content

Instantly share code, notes, and snippets.

@snadahalli
Created October 29, 2013 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snadahalli/7210164 to your computer and use it in GitHub Desktop.
Save snadahalli/7210164 to your computer and use it in GitHub Desktop.
C program to check whether a given number is prime or not.
/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/
#include<stdio.h>
main()
{
int a,c=0,i,num;
printf("Enter the number to be checked\n");
scanf("%d",&num);
for(i=1;i<num;i++)
{
a=num%i;
if(a==0)
{
c=c+1;
}
}
if (c==1)
{
printf("The given number %d is a prime\n", num);
}
else
{
printf("The given number %d is not prime\n", num);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment