Computer Science, asked by anikdebnath2000, 1 year ago

write a program to calculate the sum of all the prime numbers between the range of 1 and 100


Anonymous: In which language?
anikdebnath2000: in English ofcourse
Anonymous: I meant which programming language?

Answers

Answered by prathamesh1855
36
✪Hey There✪


Here is Your Program

public class PrimeNumber {
public class PrimeNumber { public static void main(String args[]) {
long sum = 0;
for (int number = 2; number <= 100; number++) {
if (isPrimeNumber(number)) { sum += number;
}
System.out.println(sum);
} private static boolean isPrimeNumber(int number){
for (int i = 2; i <= number / 2; i++) {
if (number % i == 0)
{ return false; } } return true;
}
}


Hope It Helps.

prathamesh1855: Mark as Brainliest
Answered by Anonymous
35
Here's a snippet of the logical expressions in Java

int a , c,sum=0, d;

for (a=1; a<=100; a++){
d=0;
for(c=1;c<=a;c++){
if(a%c==0){
d++;
}
if (d==2)
sum=sum+a;
}
}


Haven't run a check, hope it works!
Similar questions