0
Write a program for :-[(addition of all the prime no.)/2] between any two no. In c++
eg :- take two no.as 5&9. further((5+7+9)/2)is your ans
2 odpowiedzi
+ 2
#include <iostream>
#include <math.h>
using namespace std;
int prime(int a)
{
for(int i=2; i<=pow(a, 0.5); i++)
{
if(a%i==0)
return 0;
}
return 1;
}
int main() {
int x, y;
int sum=0;
cout<<"Enter Lower Limit: ";
cin>>x;
cout<<"Enter Upper Limit: ";
cin>>y;
for(int i=x; i<=y; i++)
{
if(prime(i))
sum += i;
}
cout<<"Result: "<<sum/2;
return 0;
}
+ 2
By the way 9 is not prime number