Number (C ++ / JAVA) outputs all prime numbers between 101-200 and outputs primes
C++:
#include<iostream>
using namespace std;
bool ISSS(int p) {
for (int q = 2; q <= sqrt(p); q++) {
if (p % q == 0) {
return false;
}
}
return true;
}
void SUSHU(int m, int n) {
int num = 0;
for (int p = m; p <= n; p++) {
if (ISSS(p) == true) {
num++;
cout << p << " ";
}
}
cout << endl;
cout << num << endl;
}
int main(){
SUSHU(101,200);
}
JAVA:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dm;
/**
*
* @author Lenovo
*/
public class DM {
/**
* @param args the command line arguments
*/
public static boolean ISSS(int p) {
for (int q = 2; q <= Math.sqrt(p); q++) {
if (p % q == 0) {
return false;
}
}
return true;
}
public static void SUSHU(int m, int n) {
int num = 0;
for (int p = m; p <= n; p++) {
if (ISSS(p) == true) {
num++;
System.out.print(p+" ");
}
}
System.out.println();
System.out.println(num);
}
public static void main(String[] args) {
SUSHU(101, 200);
}
}