Last active
May 7, 2023 05:48
-
-
Save amalbenny/be2bd208205dd8e80f1170f32e78e053 to your computer and use it in GitHub Desktop.
Identify whether the number is prime or not
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdbool.h> | |
void main() { | |
// PRIME NUMBER SENSOR PROGRAM | |
// GitHub: @amalbenny | |
int num,count=2; | |
bool isPrime=true; | |
printf("Prime Number Sensor program \n----------------------------------- \nEnter the number for verification: "); | |
scanf("%d",&num); | |
while(count<num){ | |
// Loops to identify is it divisible with any integer other than 1 and itself without a reminder? | |
if(num%count==0) | |
isPrime=false; | |
count++; | |
} | |
if(num<2) | |
printf("\n It's not a prime number"); | |
else | |
printf((isPrime)?"\nIt\'s a prime number.":"\nIt is not a prime number."); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
//KOTLIN version for PRIME NUMBER SENSOR PROGRAM | |
println("Enter the number: ") | |
var num= readLine()!!.toInt() | |
var count:Int=2 | |
var isPrime:Boolean=true | |
while(count<num){ | |
if(num%count==0){ | |
isPrime=false | |
} | |
count++ | |
} | |
var op:String | |
if (num<2) | |
op="It's not a prime number" | |
else if(isPrime){ | |
op="$num is a prime number" | |
} else{ | |
op="$num is not a prime number" | |
} | |
println(op) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python program to check if the input number is prime or not | |
num=int(input("Number for evaluate:")) | |
# take input from the user | |
# num = int(input("Enter a number: ")) | |
# prime numbers are greater than 1 | |
if num > 1: | |
# check for factors | |
for i in range(2,num): | |
if (num % i) == 0: | |
print(num,"is not a prime number") | |
print(i,"times",num//i,"is",num) | |
break | |
else: | |
print(num,"is a prime number") | |
# if input number is less than | |
# or equal to 1, it is not prime | |
else: | |
print(num,"is not a prime number") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment