This program will take a number as input from user and will display the number of prime numbers in the range starting from 0 to the number entered by user.
Also, it will be the sum of the prime numbers in that range.
We will be displaying program which is compatible with Dev C++.
You can download dev c++ from here
Program Code:
#include<iostream.h>
#include<conio.h>
int main()
{
int a,b,c,d,e=6;
cout<<"Enter the number upto which you want to display prime numbers in that range & to find their sum.\n";
cin>>a;
cout<<"Prime numbers in the entered range are 1,2,3";
for(c=4;c<=a;c++)
{
for(d=2;d<c;d++)
{
if(c%d==0)
{
break;
}
if(d==c-1)
{
cout<<","<<c;
e=e+c;
break;
}
}
}
cout<<"\nThe sum of prime numbers in range of "<<a<<" is "<<e;
getch();
}
Output:
