#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,temp;
int sum = 0;
cout<<"--------------------------------------\n";
cout<<" Sum of Prime Numbers from 1 to 500 \n";
cout<<"--------------------------------------\n\n";
for(a = 2 ; a <= 500 ; a++)
{
temp=0;
for(b = 2 ; b < a ; b++)
{
if(a % b == 0)
temp = 1;
}
if(temp == 0)
sum = sum + a ;
}
cout<<sum;
getch();
}
#include<conio.h>
void main()
{
clrscr();
int a,b,temp;
int sum = 0;
cout<<"--------------------------------------\n";
cout<<" Sum of Prime Numbers from 1 to 500 \n";
cout<<"--------------------------------------\n\n";
for(a = 2 ; a <= 500 ; a++)
{
temp=0;
for(b = 2 ; b < a ; b++)
{
if(a % b == 0)
temp = 1;
}
if(temp == 0)
sum = sum + a ;
}
cout<<sum;
getch();
}
No comments:
Post a Comment