Computer Science, asked by saraswat3, 1 year ago

write a program to find the sum of Prime no between 1 and 100

Answers

Answered by Anonymous
0
i have written the java program 




----------------------------------------







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);
    }
}


Answered by Pranjaljoshi792
0

Answer:

public class PrintPrimeNumbers1 {

public static void main(String[] args)

{

int i, number, count;

System.out.println(" Prime Numbers from 1 to 100 are : ");

for(number = 1; number <= 100; number++)

{

count = 0;

for (i = 2; i <= number/2; i++)

{

if(number % i == 0)

{

count++;

break;

}

}

if(count == 0 && number != 1 )

{

System.out.print(number + " ");

}

}

}

}

Hope it helps.

Similar questions