My Math Forum Computer program for printing Prime numbers in reverse order.

 Computer Science Computer Science Forum

 March 8th, 2019, 08:08 PM #1 Banned Camp   Joined: Nov 2018 From: Mumbai Posts: 32 Thanks: 1 Computer program for printing Prime numbers in reverse order. https://www.rapidtables.com/math/num...e_numbers.html I would like to write a computer program which will print prime numbers starting from 100 till 0. i.e. reverse order. Can I get the source code written in any programming language C,C++,Java,C#, Python etc? Thanks & Regards, Prashant S Akerkar Last edited by akerkarprash; March 8th, 2019 at 08:13 PM.
 March 9th, 2019, 01:04 AM #2 Banned Camp   Joined: Nov 2018 From: Mumbai Posts: 32 Thanks: 1 Thanks. Output of the program should be 97,89,83,79 and so on till 3. Or 97 89 83 79 till 3 Thanks & Regards, Prashant S Akerkar Last edited by akerkarprash; March 9th, 2019 at 01:04 AM. Reason: Content updates.
 March 9th, 2019, 02:19 AM #3 Global Moderator   Joined: Dec 2006 Posts: 20,373 Thanks: 2010 The code can calculate the primes in ascending order: 2, 3, 5, etc., storing the results, then print them in descending order.
 March 9th, 2019, 03:26 AM #4 Banned Camp   Joined: Nov 2018 From: Mumbai Posts: 32 Thanks: 1 Thanks. Can I have the source code? This could be in any programming language viz C,C++,Java,C#, Python etc Thanks & Regards, Prashant S Akerkar
 March 9th, 2019, 05:00 AM #5 Senior Member   Joined: Oct 2015 From: Greece Posts: 107 Thanks: 6 Code: #!/usr/bin/env python3 start = 100 end = 2 #This List will hold the prime numbers. prime_numbers = [] #Loop from 100 to 2. for number in range(start, end-1, -1): #Flag is_prime = True #Loop from 2 to number-1 for trial_number in range(2, number): #If at least one trial_number divide's #the number perfectly (the remainder is zero) #then this is not a prime number. if number % trial_number == 0: is_prime = False break #Check if this number has been validated as a prime number. #If yes, append it to the List. if is_prime: prime_numbers.append(number) #Print the result. for prime in prime_numbers: print(prime)
 March 9th, 2019, 09:10 AM #6 Banned Camp   Joined: Nov 2018 From: Mumbai Posts: 32 Thanks: 1 Thanks. Is the above source code written in Python programming language? I would like to test by running the program for getting the desired output. Thanks & Regards, Prashant S Akerkar
 March 9th, 2019, 09:53 AM #7 Math Team   Joined: Oct 2011 From: Ottawa Ontario, Canada Posts: 14,124 Thanks: 1003 Using UBasic: for n = 99 to 3 step -1 if prmdiv(n) = n then print n next n Ahem!
 March 9th, 2019, 10:46 AM #8 Banned Camp   Joined: Nov 2018 From: Mumbai Posts: 32 Thanks: 1 Thanks. Can we term this new series as Reverse Prime numbers series? Thanks & Regards, Prashant S Akerkar
March 9th, 2019, 10:56 AM   #9
Math Team

Joined: Oct 2011

Posts: 14,124
Thanks: 1003

Quote:
 Originally Posted by akerkarprash Thanks. Can we term this new series as Reverse Prime numbers series? Thanks & Regards, Prashant S Akerkar
Prashant, go play in the traffic during rush hour

March 9th, 2019, 11:02 AM   #10
Senior Member

Joined: Aug 2012

Posts: 2,204
Thanks: 647

Quote:
 Originally Posted by akerkarprash Thanks. Is the above source code written in Python programming language? I would like to test by running the program for getting the desired output. Thanks & Regards, Prashant S Akerkar
Here is the program you need. It's Python 3.

print("97,89,83,79,73,71,67,61,59,53,47,43,41,37,3 1,29,23,19,17,13,11,7,5,3,2")

Last edited by Maschke; March 9th, 2019 at 11:55 AM.

 Tags computer, number, numbers, order, prime, printing, program, reverse

 Thread Tools Display Modes Linear Mode

 Similar Threads Thread Thread Starter Forum Replies Last Post akerkarprashant Computer Science 0 November 2nd, 2018 09:50 PM prashantakerkar Applied Math 5 March 31st, 2017 06:46 AM grogmachine Computer Science 10 June 20th, 2011 05:05 AM Hoempa Computer Science 0 June 21st, 2010 05:37 AM ElMarsh New Users 19 September 20th, 2009 02:53 PM

 Contact - Home - Forums - Cryptocurrency Forum - Top