Prime numbers (1 to 100) and their sum | 1 - 100 Prime number
# include <iostream>
using namespace std;
void main()
{
int num=0;
int prime=0;
int sum=0;
while (num<=100) // for 100 prime numbers
{
int count= 0;
int i = 1;
while(i<=num){ // for checking prime or not
if(num%i==0){
count++; // to save every divider
}
i++;
}
if(count==2){
prime=num;
cout<<prime<<endl;
sum=sum+prime;
}
num++;
}
cout<<"The sum is :"<<sum<<endl;
}
Comments
Post a Comment