Home » C Programs » Prime or Not in C Using Function

In this program, we can find whether the number is prime or not.

Prime numbers are those that have only two elements, namely one and the number itself. To put it another way, prime numbers can only be divided by one and the number itself.

That is, they cannot be divided by any other number. A prime number is a number higher than one that is not the product of two lesser natural numbers. A composite number is a natural number greater than 1 that is not prime.

A function is a collection of statements that work together to complete a task. Every C program contains at least one function, main(), and even the simplest programmes can specify more functions.

The name, return type, and parameters of a function are all specified in a function declaration. A function is a logical unit of code that is frequently defined by its place in a larger code structure.

A function is a unit of code that works on a variety of inputs, many of which are variables, and provides real outcomes such as changing variable values or doing actual operations based on the inputs. By using this function method we have executed the prime or not in c using function

```
//prime or not in c using function
#include<stdio.h>
int main()
{
int num,res=0;
printf("\nEnter The Number");
scanf("%d",&num);
res=prime(num);
if(res==0)
printf("\n%d Is a Prime Number",num);
else
printf("\n%d Is a Not Prime Number",num);
}
int prime(int n)
{
int i;
for(i=2;i<=n/2;i++)
{
if(n%i!=0)
continue;
else
return 1;
}
return 0;
}
```

Output:

Enter The Number 45

45 Is a Not Prime Number