Skip to content

Instantly share code, notes, and snippets.

@wasit-shafi
Created May 29, 2020 04:53
Show Gist options
  • Save wasit-shafi/8c51fca47feaf5e67a80fef401619671 to your computer and use it in GitHub Desktop.
Save wasit-shafi/8c51fca47feaf5e67a80fef401619671 to your computer and use it in GitHub Desktop.
#include<stdio.h>
int isPrime(int n , int i)
{
if(n < 2) return 0;
if(n == 2) return 1;
if(n % i == 0) return 0;
if(i * i > n) return 1;
isPrime(n, i + 1);
}
int main()
{
int n;
printf("Enter Value of n... ");
scanf("%d", &n);
if(isPrime(n, 2))
printf("%d is a Prime Number.", n);
else
printf("%d is not a Prime Number.", n);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment