Write a program that accepts an input integer n, and calculates the
number and sum of all the numbers between 1 and n (inclusive) that are
NOT evenly divisible by ANY of the first 5 prime numbers (2,3,5,7,11).
The program should print out a clearly labeled count and sum
my code is : it is not
Clarification : The number (count) is the number of elements between 1 and n
which are not evenly divisible by 5 prime numbers
and the result is the sum of all the numbers between 1
and n which are not evenly divisible by 5 prime numbers . Right???
For Example : if n=5 then
val = 2*3*5*7*11
for(i = 0 to n-1)
if(val%a[i] == 0)
count++,sum+=a[i];
surender
On Tue, Jul 5, 2011 at 10:10 PM, Rajeev Bharshetty
rajeev.open.1...@gmail.com wrote:
Clarification : The number (count) is the number of elements between 1 and
n which are not evenly divisible by 5 prime
I think you are getting it wrong.
Surender, your solution says that numbers divisible by all of the first 5
prime numbers will be taken into account whereas the question says that only
the numbers *not* evenly divisible by *any* of the first 5 prime numbers are
to be added.
Shiv,
you are making
If my interpretation is right, following should be the code.
int main()
{
int userInteger = 0;
cout Enter A Number endl;
cin userInteger; // Ask For a number from the user
if (userInteger 0) // Is the number valid?
{
int result = 0;
int prime[5] = { 2, 3, 5, 7, 11 };
int a,b, count = 0;