Answer to Question #16595 in C++ for Abedmasri

Question #16595
a c++ program that calculates and displays the sum of all prime numbers in a user-defined closed interval [a,b] of positive integers using both pre-defined and user-defined functions.
1
Expert's answer
2012-10-19T08:57:46-0400
#include "iostream"
using namespace std;

int isprime(int valuex){
int x,j;
x=1;
& for (j=2 ; j<valuex; j++)
{ if ((valuex%j)==0) x=0; }
& if(x!=0) return 1;
& else return 0;
}

int a,b;

void main(){
cout<<"primes from "<<a<<" to "<<b<<":\n";
a=10; b = 101;
for (int i=a; i<=b; i++)
& if (isprime(i)) cout<<i<<" ";
cout<<"\n";
cout<<"enter a:";
cin>>a;
cout<<"enter b:";
cin>>b;
cout<<"primes from "<<a<<" to "<<b<<":\n";
for (i=a; i<=b; i++)
& if (isprime(i)) cout<<i<<" ";
cout<<"\n";
system("pause");
}



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS