Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save scratchyourbrain/b81fcb6b30eccc75b8f1 to your computer and use it in GitHub Desktop.

Select an option

Save scratchyourbrain/b81fcb6b30eccc75b8f1 to your computer and use it in GitHub Desktop.

Revisions

  1. scratchyourbrain created this gist Dec 24, 2014.
    20 changes: 20 additions & 0 deletions C Program to Check Whether a Number is Prime or Not
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #include <stdio.h>
    int main()
    {
    int n, i, flag=0;
    printf("Enter a positive integer: ");
    scanf("%d",&n);
    for(i=2;i<=n/2;++i)
    {
    if(n%i==0)
    {
    flag=1;
    break;
    }
    }
    if (flag==0)
    printf("%d is a prime number.",n);
    else
    printf("%d is not a prime number.",n);
    return 0;
    }