LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-03-2006, 03:39 AM   #1
dicksonmakts
LQ Newbie
 
Registered: Apr 2006
Posts: 3

Rep: Reputation: 0
define Primary number or not...


hello, everybody...
i'm newbie in shell script..
here i have a question want to ask you all, hope someone can give a hand to me and solve the problem

Question:

Write a shell program to find the given number is primary or not.

anyone know how to slove, please kindly send me a mail.
thank you very much..
 
Old 04-03-2006, 04:06 AM   #2
Randux
Senior Member
 
Registered: Feb 2006
Location: Siberia
Distribution: Slackware & Slamd64. What else is there?
Posts: 1,705

Rep: Reputation: 55
What's a primary number? Is this your homework assignment?
 
Old 04-03-2006, 04:21 AM   #3
dicksonmakts
LQ Newbie
 
Registered: Apr 2006
Posts: 3

Original Poster
Rep: Reputation: 0
Primary number..

yaya.. that is my homewrok assignment..because i'm really new in this script,do not have any idea to do it. so need some help here..

question description:

when user enter the number, it will define the number whether primary number or not. *primary number is 1,2,3,5,7,11,13,.... (cannot be devided by some number)

hope anyone can help me..
thanks..

Last edited by dicksonmakts; 04-03-2006 at 04:30 AM.
 
Old 04-03-2006, 06:51 AM   #4
MRMadhav
Member
 
Registered: Nov 2005
Location: Mauritius
Distribution: PCQLinux, SUSE Linux,Fedora Core 5, Fedora Core 6, Knoppix Live, Kubuntu Edgy, PCLinuxOS
Posts: 167

Rep: Reputation: 30
Though I also don't know shell scripts, I would rather advise you to get the method of knowing that procedure from a maths teacher. There should be a calculation to know how to know this effectively then afterwards it will be easy to implement it in any language!
 
Old 04-03-2006, 07:19 AM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
Do not expect LQ members to do your homework - you will learn much more by doing it yourself.

http://www.linuxquestions.org/rules.php
 
Old 04-03-2006, 07:31 AM   #6
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
There are many algorithms for determining what you want. The most well known being the Sieve of Eratosthenes. It would do you well to understand the procedure BEFORE you try to develop code to do it for you! Once you've figured out HOW to do your own homework, you might be able to ask LQ about some script commands that will implement the algortihm.

Incidently, they are not primary numbers. They are called prime numbers.
 
Old 04-04-2006, 09:28 AM   #7
Randux
Senior Member
 
Registered: Feb 2006
Location: Siberia
Distribution: Slackware & Slamd64. What else is there?
Posts: 1,705

Rep: Reputation: 55
I want to see the guy who codes that in bash!
 
Old 04-04-2006, 06:16 PM   #8
addy86
Member
 
Registered: Nov 2004
Location: Germany
Distribution: Debian Testing
Posts: 332

Rep: Reputation: 31
Quote:
Originally Posted by Randux
I want to see the guy who codes that in bash!
I want to see him waiting for the results.
 
Old 04-04-2006, 07:43 PM   #9
mfrick
Member
 
Registered: Sep 2004
Location: Perth
Posts: 51

Rep: Reputation: 15
prime number is a number that is only divisible by one and itself.


may be small flaws in below algorithm but should basically work ....


prime=0 #just using as toggle 0=default(prime), 1=not prime
divisor=2 # start at 2 because all numbers are divis by 1

get number

# in while loop divisor cant be bigger than 1/2 number because
# well basic maths gives an answer to that

while (divisor <= number/2) and (prime=0)
remainder = number%divisor # where % returns the remainder of the division
if remainder=0
prime=1
end if
increment divisor
end while

if prime=1
print that number is not prime
else
print number is prime


Quote:
I want to see the guy who codes that in bash!
I reckon I could write that (or something similar) in bash. I'm not gonna do homework for someone.

Last edited by mfrick; 04-04-2006 at 07:46 PM.
 
Old 04-04-2006, 11:04 PM   #10
dicksonmakts
LQ Newbie
 
Registered: Apr 2006
Posts: 3

Original Poster
Rep: Reputation: 0
thanks you all reply..
i foind the solution already..


THANKS VERY MUCH
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Running Fedora 4 on primary master and cant acsess my xp files on primary slave roxberry1 Linux - Newbie 5 01-29-2006 11:37 AM
Dual boot primary Linspire & XP primary slave? watmonki Linspire/Freespire 5 11-01-2005 08:16 PM
DNS security / primary names server down after large number of requests rioguia Linux - Security 4 10-08-2004 10:00 AM
DNS security / primary names server down after large number of requests rioguia Linux - Networking 1 10-07-2004 11:27 AM
boot loader, MBR, redhat9 on primary slave, winxp on primary master samik Linux - Hardware 4 10-15-2003 08:55 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration