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 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 > count ->2 (i.e 1 and 3 ) > and result = 5 > > If I am wrong ,Please Correct me and give me the outputs expected > > Thank You > > Rajeev N B > > > On Tue, Jul 5, 2011 at 12:17 PM, shiv narayan > <narayan.shiv...@gmail.com>wrote: > >> 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 giving correct result >> >> #include <iostream> >> #include<conio.h> >> using namespace std; >> 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 = 1, count = 0; >> while (a < userInteger) // Looping to user's input >> { >> int b = 0; >> while (b < 5) // Looping the prime numbers array >> { >> if (a % prime[b]) >> { >> result += a; // If Not evenly divisible by prime number at index 'b' >> count++; >> } >> b++; >> } >> a++; // Increment the counter >> } >> cout << "Numbers Not evenly divisible by 5 prime numbers: " << count >> << endl; >> cout << "The Sum of numbers not evenly divisible by 5 prime numbers: " >> << result << endl; >> } >> getch(); >> return 0; >> } >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> >> > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.