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"); }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment