InterviewSolution
Saved Bookmarks
| 1. |
WAP in java to calculate the sum of all prime numbers between 1 to 100 . |
| Answer» ASS prime_sum{public VOID main(){int s=0;int c=0;for(int i=1;i<=100;i++){c=0;for(int j=1;j<=i;j++){if(j%i==0){c++;}}if(c==2){s=s+i;}}//end of for-loop}//end of main}//end of classNote :The prime logic is given so that PRIMES have 2 and only 2 factors.Hope it HELPS :-)________________________________________________________ | |