By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,501 Members | 2,805 Online
Bytes IT Community
+ Ask a Question
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
Share this Question
Share on Google+
7 Replies


gpraghuram
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<n;i++)
If (n Mod i = 0) Then // if (n %i =0)
x = True
End If
Next //Close for brace
If x = True Then
MsgBox("Not a Prime") //Printf function.
Else
MsgBox("Prime")
End If
Jun 13 '07 #4

weaknessforcats
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
  1. printf("Please enter two integers:  9 13\n");
  2. printf("                             9:        3\n                           10:        2     5\n");
  3. printf("                           11:        Prime\n                           12:        2    3   4    6\n");
  4. printf("                           13:  Prime\n     There are 2 prime numbers.\n");
  5. printf("      The average value of the prime numbers is 12.00\n");
  6. printf("  Please enter two integers.\n");
  7.  
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
  1. printf("Please enter two integers:  9 13\n");
  2. printf("                             9:        3\n                           10:        2     5\n");
  3. printf("                           11:        Prime\n                           12:        2    3   4    6\n");
  4. printf("                           13:  Prime\n     There are 2 prime numbers.\n");
  5. printf("      The average value of the prime numbers is 12.00\n");
  6. printf("  Please enter two integers.\n");
  7.  
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

Post your reply

Sign in to post your reply or Sign up for a free account.