Write a C program to Check whether a given number is a prime or not using pointer
Program:-
#include<stdio.h>
int is_prime_number(int *p)
{
int i;
for(i = 2; i <= *p/2; i++)
{
if(*p % i ==0)
{
break;
}
}
if(i > *p/2)
printf(“\n%d is a Prime Number\n”,*p);
else
printf(“\n%d is not a Prime Number\n”, *p);
}
int main()
{
int n,i;
printf(“\nEnter the number : “);
scanf(“%d”,&n);
int *p = &n;
is_prime_number(p);
return 0;
}
int is_prime_number(int *p)
{
int i;
for(i = 2; i <= *p/2; i++)
{
if(*p % i ==0)
{
break;
}
}
if(i > *p/2)
printf(“\n%d is a Prime Number\n”,*p);
else
printf(“\n%d is not a Prime Number\n”, *p);
}
int main()
{
int n,i;
printf(“\nEnter the number : “);
scanf(“%d”,&n);
int *p = &n;
is_prime_number(p);
return 0;
}
Output:-
....
0 comments:
Post a Comment