/*
* This Java program calculates and prints the sum of all prime numbers
* between 1 and 100.
*/
class prime1To100
{
public static void main()
{
int sum=0,i,k,j;
for(i=1;i<100;i++)
{
k=0;
for(j=2;j<i;j++)
{
if(i%j==0)
{
k=1;
break;
}
}
if(k==0)
{
sum=sum+i;
}
}
System.out.println("Sum = "+sum);
}
}
//Author : Mayank Rajoria
No comments:
Post a Comment