Write a Haskell function called isPrime that determines if a

Write a Haskell function called isPrime that determines if an Integer is a prime number (evenly divisible only by itself and one).

Solution

Python


#!/usr/bin/python
num = input(\'Enter the number which you wish to determine it is prime: \')

if num < 2:
print \"\ The Number\", num, \" is not a prime!\"
else:
for div in range(2, (num/2)+1):
if num%div==0:
print \"\ The Number\", num, \" is not a prime!\"
break
else:
print \"\ The Number\", num, \" is a prime!\"


C

#include<stdio.h>

int main()
{
int div;
int num;

printf(\"Enter a number: \");
scanf(\"%d\", &num);

if(num>=2)
for(div=2; div <= num/2; div++)
if((num%div)==0)
break;

if(num>1 && (!(div<=num/2)))
printf(\"\ The number %d is a prime.\", num);
else
printf(\"\ The number %d is not a prime\", num);

return 0;
}



C++

#include<iostream>
using namespace std;

int main()
{
int div;
int num;

cout<<\"Enter a number: \";
cin>>num;

if(num>=2)
for(div=2; div <= num/2; div++)
if((num%div)==0)
break;

if(num>1 && (!(div<=num/2)))
cout<<\"The number \"<<num<<\" is a prime\ \";
else
cout<<\"The number \"<<num<<\" is not a prime\ \";


return 0;
}

Write a Haskell function called isPrime that determines if an Integer is a prime number (evenly divisible only by itself and one).SolutionPython #!/usr/bin/pyth
Write a Haskell function called isPrime that determines if an Integer is a prime number (evenly divisible only by itself and one).SolutionPython #!/usr/bin/pyth

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site