#include<iostream>
using namespace std;
int main()
{
int a,i,j,sum=0;
cout<<"Enter a range:";
cin>>a;
for(i=2;i<=a;++i)
{
int flag=1;
for(j=2;j<=i;++j)
{
if(i%j==0)
{
flag=0;
break;
}
}
if(flag==1)
sum+=i;
}
cout<<sum;
return 0;
}
using namespace std;
int main()
{
int a,i,j,sum=0;
cout<<"Enter a range:";
cin>>a;
for(i=2;i<=a;++i)
{
int flag=1;
for(j=2;j<=i;++j)
{
if(i%j==0)
{
flag=0;
break;
}
}
if(flag==1)
sum+=i;
}
cout<<sum;
return 0;
}
0 comments:
Post a Comment