Prime number using function

Program:

#include<stdio.h>
int isprime(int num);
int main()
{
int n;
printf("Enter Number: ");
scanf("%d",&n);
if(isprime(n)==1)
{
printf("%d is prime",n);
}
else
{
    printf("%d is not prime",n);
}
    return 0;
}
int isprime(int num)
{
    int i;
for(i=2;i<num;i++)
{
if((num%i)==0)
{
return 0;
}
}
return 1;
}

Output:



No comments:

Post a Comment

x^y using recursion

Program: #include<stdio.h> int power(int a,int b); int main() { int x,y,ans; printf("Enter x and y:\n "); scanf(...