# Answer to Question #49514 in C for faaz

Question #49514

a prgram which takes input from user & test that number is prime number using functions?

Expert's answer

#include <iostream>

#include <math.h>

#include "stdio.h"

int PrimeDetector(int user_number){

int usernumber=user_number;

int PrimeDetectorStatus=1;

if (usernumber==2) PrimeDetectorStatus=1;

if (usernumber==3) PrimeDetectorStatus=1;

int limit = round(usernumber/2);

for (int i=2;i<limit;i++)

{

if (usernumber%i==0) {PrimeDetectorStatus =0;break;}

}

return PrimeDetectorStatus;

}

using namespace std;

int main()

{

int user_number;

cout<<"Input Your number:";

cin>>user_number;

if (PrimeDetector(user_number)==1) cout<<"You number is prime";

else cout<<"You number is not prime";

return 0;

}

#include <math.h>

#include "stdio.h"

int PrimeDetector(int user_number){

int usernumber=user_number;

int PrimeDetectorStatus=1;

if (usernumber==2) PrimeDetectorStatus=1;

if (usernumber==3) PrimeDetectorStatus=1;

int limit = round(usernumber/2);

for (int i=2;i<limit;i++)

{

if (usernumber%i==0) {PrimeDetectorStatus =0;break;}

}

return PrimeDetectorStatus;

}

using namespace std;

int main()

{

int user_number;

cout<<"Input Your number:";

cin>>user_number;

if (PrimeDetector(user_number)==1) cout<<"You number is prime";

else cout<<"You number is not prime";

return 0;

}

## Comments

## Leave a comment