60 475
Assignments Done
98,1%
Successfully Done
In April 2018

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.
Expert's answer
#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions