Fakultas Ilmu Komputer UI

Commit ac6a7f0f authored by Ardhi Putra Pratama's avatar Ardhi Putra Pratama
Browse files

add other prime lang

parent b38d2888
#!/bin/bash
total=0
lower=2
upper=1234567
startTime=`date +%s`
for (( i=2;i<$upper;i++ ))
do
isprime=1
for (( j=2;j<i;j++ ))
do
moduloOp=$(( $i % $j ))
if [ $moduloOp = 0 ]
then
isprime=0
break
fi
done
total=`expr $total + $isprime`
done
echo $total
endTime=`date +%s`
elapsedTime=`expr $endTime - $startTime`
echo $elapsedTime
import time
total = 0
lower = 2
upper = 1234567
start_time = time.time();
for i in range(lower,upper):
isprime = 1
for j in range(2,i):
if (i % j == 0):
isprime = 0
break
total += isprime
elapsed_time = time.time() - start_time
print("Number of Prime Numbers = ",total)
print("Execution Time = ", elapsed_time)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment