SUMMER TRAINING Free Tutorials  Go To Your University  Placement Preparation 
Project Based Best Summer Training Courses in Jaipur
Join our Telegram Channel To take free Online Courses
0 like 0 dislike
38 views

1 Answer

0 like 0 dislike
by Goeduhub's Expert (7.1k points)
edited by
 
Best answer

Prime Number Evaluation Using Function

In this program we are going to evaluate if a number is prime number or not using functions in C programming.

To learn basics of function in C programming Click Here.

Example :

#include<stdio.h>
#include<conio.h>

//Declaration of prime funtion
int prime(int x);

void main()
{
int x;
clrscr();

//Taking number from the user to check if it's prime or not
printf("\nEnter a number:");
scanf("%d",&x);

//calling prime number for true of false
if(prime(x))
printf("\nNumber is Prime");
else
printf("\nNumber is not prime");
getch();
}

//Definition of prime function
int prime(int n)
{
int checkprime=0,i;
for(i=2;i<n;i++)
{
if(n%i==0)
checkprime=1;
}
if(checkprime==0)
return 1;
else
return 0;
}

Output :

Output of above program showing prime number


For More GTU C Programming Lab Experiments Click Here

Our Mentors(For AI-ML)


Sharda Godara Chaudhary

Mrs. Sharda Godara Chaudhary

An alumna of MNIT-Jaipur and ACCENTURE, Pune

NISHA (IIT BHU)

Ms. Nisha

An alumna of IIT-BHU

Related questions

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 
...