program to find sum of first fifty prime even number.
Answers
Answer:
Program to find the sum of first fifty prime number.
Explanation:
Code of the above program:
#include <stdio.h>
int main()
{
int i, j, isPrime, sum=0;
int n= 50 */ you can also initiate in the for loop rather than defining here */
/* Input upper limit from user */
printf("Find sum of first fifty prime between 1 to n: ");
scanf("%d", &n);
/* Find first fifty prime numbers between 1 to n */
for(i=2; i<=n; i++)
{
isPrime = 1;
for(j=2; j<=i/2 ;j++)
{
if(i%j==0)
{
isPrime = 0;
break;
}
}
if(isPrime==1)
{
sum += i;
}
}
printf("Sum of first fifty prime numbers between 1 to n %d = %d", n, sum);
return 0;
}
class s1upv
{
public static void main ()
{ int s= 0;
for (int i= 0 ; i<= 50 ; i++)
{ for (int j=0 ; j<= i ; j++)
{ if ( i% j = = 0 && i%2 ==0)
{s = s+ i ;
}
}}
system .out.println ( "sum is :"+ s );
}}