Skip to content

Instantly share code, notes, and snippets.

@BhJaipal
Last active March 18, 2023 11:16
Show Gist options
  • Save BhJaipal/4f1e3833ff84fcedc7610a263c56578c to your computer and use it in GitHub Desktop.
Save BhJaipal/4f1e3833ff84fcedc7610a263c56578c to your computer and use it in GitHub Desktop.
Prime Numbers
using System;
public class PrimeNumber{
public static void main(String[] args) {
Console.WriteLine("Enter limit: ");
primeNums(int.Parse(Console.ReadLine()));
}
static void primeNums(int num) {
int zeros;
for (int i= 2; i<= num; i++) {
zeros= 0;
for (int j= 2; j<= i/2; j++) {
if (i%j == 0) {
zeros++;
}
}
if (zeros == 0) {
Console.WriteLine(i);
}
}
}
}
import java.util.Scanner;
public class PrimeNumber{
public static void main(String[] args) {
System.out.print("Enter limit: ");
primeNums(new Scanner(System.in).nextInt());
}
static void primeNums(int num) {
int zeros;
for (int i= 2; i<= num; i++) {
zeros= 0;
for (int j= 2; j<= i/2; j++) {
if (i%j == 0) {
zeros++;
}
}
if (zeros == 0) {
System.out.println(i);
}
}
}
}
function PrimeNums(num) {
for (let i= 2; i<= num; i++) {
let zeros = 0;
for (let j= 2; j<= i/2; j++) {
if (i%j == 0) {
zeros++;
}
}
if (zeros == 0) {
console.log(i);
}
}
}
PrimeNums(window.prompt("Enter limit: "));
def primeNums(num: int):
for i in range(2, num):
zeros= 0;
for j in range(2, i/2):
if (i%j == 0):
zeros+=1;
if (zeros == 0):
print(i);
primeNums(int(input("Enter limit: ")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment