435,501 Members | 2,805 Online
Need help? Post your question and get tips & solutions from a community of 435,501 IT Pros & Developers. It's quick & easy.

# Prime Number Programming

 P: 1 I Am Facing A Problem Working With Prime Number. Could You Send The Code? From, Chetna Jun 13 '07 #1
7 Replies

 Expert 100+ P: 1,275 This is against Posting guidelines. Have you tried solving the issue/problem.? Raghuram Jun 13 '07 #2

 P: 93 I Am Facing A Problem Working With Prime Number. Could You Send The Code? From, Chetna I cannot send you the code. Your problem is not defined clearly. "Working with Prime number" means what ? Are you manipulating prime numbers ? If you want to display prime numbers, then this is the algorithm 1. put a for loop from 4 to the highest number you want [ for example 1 to 100 print prime numbers, like wise] Here 2,3 are prime numbers print them directly if they are in the range. 0 and 1 are neither prime nor composite so leave them. 2. Have a flag with initial value true 3. Nest with another for loop, Let the variable of outer for loop be i and inner be j 4. Now intialise j from zero to square root of i 5. In this inner loop check whether j divides i, that is reminder is zero make use of "%" operator. 6. If the reminder is zero, then make the flag false and break the inner loop 7. After inner loop, before closing outer loop; check the flag, if it is true then display variable i, since it is prime and close the outer for loop Is it all clear now ??? Post whether this is the one you are looking for Regards, Girish. Jun 13 '07 #3

 P: 22 Hi this is the code for vb.net To find the given no is prime or not.The same syntax and formulae using in C.So try it . Dim n, i As Integer Dim x As Boolean //Delclaration n = TextBox1.Text //Using Scanf function to get the no For i = 2 To n - 1 //for(i=2;i

 Expert Mod 5K+ P: 9,197 What does your C or C++ code look like? Jun 13 '07 #5

 P: 3 how are you doing......Name is Jane what is the easiest code that would give the following output.... Please enter two integers: 9 13 9: 3 10: 2 5 11: Prime 12: 2 3 4 6 13: Prime There are 2 prime numbers. The average value of the prime numbers is 12.00 Please enter two integers. email :eutykeli@comcast.net Jun 20 '07 #6

 Expert 10K+ P: 11,448 how are you doing......Name is Jane what is the easiest code that would give the following output.... Please enter two integers: 9 13 9: 3 10: 2 5 11: Prime 12: 2 3 4 6 13: Prime There are 2 prime numbers. The average value of the prime numbers is 12.00 Please enter two integers. email :eutykeli@comcast.net Expand|Select|Wrap|Line Numbers printf("Please enter two integers:  9 13\n"); printf("                             9:        3\n                           10:        2     5\n"); printf("                           11:        Prime\n                           12:        2    3   4    6\n"); printf("                           13:  Prime\n     There are 2 prime numbers.\n"); printf("      The average value of the prime numbers is 12.00\n"); printf("  Please enter two integers.\n");   You're welcome. kind regards, Jos ps. maybe one big puts() would've been better? simpler? Jun 20 '07 #7

 P: 79 Expand|Select|Wrap|Line Numbers printf("Please enter two integers:  9 13\n"); printf("                             9:        3\n                           10:        2     5\n"); printf("                           11:        Prime\n                           12:        2    3   4    6\n"); printf("                           13:  Prime\n     There are 2 prime numbers.\n"); printf("      The average value of the prime numbers is 12.00\n"); printf("  Please enter two integers.\n");   You're welcome. kind regards, Jos ps. maybe one big puts() would've been better? simpler? LOL, I wonder if he'll really hand this in/ Jun 20 '07 #8