473,545 Members | 3,075 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Prime Number Programming

1 New Member
I Am Facing A Problem Working With Prime Number.
Could You Send The Code?
From,
Chetna
Jun 13 '07 #1
7 4398
gpraghuram
1,275 Recognized Expert Top Contributor
This is against Posting guidelines.
Have you tried solving the issue/problem.?

Raghuram
Jun 13 '07 #2
Girish Kanakagiri
93 New Member
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
krndhi1983
22 New Member
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
9,208 Recognized Expert Moderator Expert
What does your C or C++ code look like?
Jun 13 '07 #5
eutynem
3 New Member
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@comca st.net
Jun 20 '07 #6
JosAH
11,448 Recognized Expert MVP
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@comca st.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
ahammad
79 New Member
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

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

Similar topics

36
8352
by: Dag | last post by:
Is there a python module that includes functions for working with prime numbers? I mainly need A function that returns the Nth prime number and that returns how many prime numbers are less than N, but a prime number tester would also be nice. I'm dealing with numbers in the 10^6-10^8 range so it would have to fairly efficient Dag
9
2692
by: Greg Brunet | last post by:
In doing some testing of different but simple algorithms for getting a list of prime numbers, I ended up getting some results that seem a bit contradictory. Given the following test program (testPrimes.py) with two algorithms that both check for primes by testing only odd numbers using factors up to the square root of the value, where Primes1...
11
5926
by: lostinpython | last post by:
I'm having trouble writing a program that figures out a prime number. Does anyone have an idea on how to write it? All I know is that n > 2 is prim if no number between 2 and sqrt of n (inclusivly) evenly divides n.
11
7139
by: don | last post by:
Ok, this is a homework assignment, but can you help me out anyway...... I need a routine for figuring out if a number inputted by the user is a prime number or not...... all I'm asking for is Not the exact code ( well maybe a little) but the logic or algorithm to tell whether or not a number is prime....
7
7368
by: brian.digipimp | last post by:
Write a program that prompts the user to input a positive integer. It should then output a message indicating whether the number is a prime number. (Note: An even number is prime if it is 2. An odd integer is prime if it is not divisible by an odd integer less than or equal to the square root of the number.) I was given this assignment in my...
32
76378
by: Cmorriskuerten | last post by:
HI, is this is this solution to test if a number is a prime number or not: /* * Is n a prime number? * Return TRUE (1): n is a prime number * Return FALSE (0): n is a *not* a prime number */ int is_prime_number(int n)
60
1950
by: rhle.freak | last post by:
Here is my code to generate prime numbers.It works absolutely fine when the range is *not very large*. However on initializing i with a large integer it produces erroneous results (some numbers ending in 5 ..which obviously cannot be prime numbers) can anyone please help me out with the reason?? /*Generate Prime Numbers*/...
7
4885
by: newstips6706 | last post by:
1, 2, 3, 5, 7... PRIME Numbers ________________________________ Definitions What is a PRIME Number ?
2
2586
by: QHorizon | last post by:
Hello, I'm new to Python (I've learned everything up to iterators so far) and fairly new to Programming. This would be my first real program: #Coordinate Geometry (The whole program is not shown) import math import sys print "Welcome to the Coordinate Geometry Calculator!"
0
7464
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7805
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7413
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
4943
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3449
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1874
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
700
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.