Sponsored Content
Top Forums UNIX for Dummies Questions & Answers A perfect number shell program Post 302359671 by Cyansnow on Wednesday 7th of October 2009 06:40:16 AM
Old 10-07-2009
A perfect number shell program

Here's my work of testing whether a number input is perfect or not..

Code:
echo Enter a number
read no
i=1
ans=0
while [ $i -le 'expr $no / 2' ]
   do
       if [ 'expr $no % $i' -eq 0 ]
       then
          ans='expr $ans + $i'
       fi
       i='expr $i + 1'
done
if [ $no -eq $ans ]
then
echo $no is perfect
else
echo $no is NOT perfect
fi

Something has to be done in place of 'expr $no / 2'.. but I don't know..

Any idea guys.. ?

PS> you can provide me with a whole new program of tesing whether a number input from the keyboard is perfect or not.. if you guys can't fix the problem of this program..

Thanks in advance.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Write a shell program to find the sum of alternate digits in a given 5-digit number

Hi Can any one please post the answer for the above program.................. (4 Replies)
Discussion started by: banta
4 Replies

2. Shell Programming and Scripting

Prime Number Program (Fun)

Hi, I was just wondering if anyone has, or knows where to download a prime number finder program. I would like a fairly simple bash program, and also I would like one that could take advantage of multiple processors. I have 500 cores I can use, and would like to take advantage of them using a... (2 Replies)
Discussion started by: Kweekwom
2 Replies

3. Shell Programming and Scripting

extraction of perfect text from file.

Hi All, I have a file of the following format. <?xml version='1.0' encoding='utf-8'?> <tomcat-users> <role rolename="tomcat"/> <role rolename="role1"/> <role rolename="manager"/> <role rolename="admin"/> <user username="tomcat" password="tomcat" roles="tomcat"/> <user... (5 Replies)
Discussion started by: nua7
5 Replies

4. UNIX for Dummies Questions & Answers

Script producing error, Program to calculate maximum number

Hi folks, Here i have written a shell script to calculate a maximum number from 10 numbers entered on command line. max=0 echo Enter 10 numbers , one at a time for i in 1 2 3 4 5 6 7 8 9 10 do read n max=`expr $max + $n` if --- At this last step there is some problem, it gives error... (5 Replies)
Discussion started by: rits
5 Replies

5. AIX

I want the perfect user-interface

I've got an aix-box somewhere on the network and a PC on my desk. Nothing fancy so far. The PC is made dual-boot: - windowsXP with putty & winSCP or - slackware 13 with xfce4 installed. The aix-box runs DB2 v8.2 and I've installed db2top to monitor the database. db2top is a character... (0 Replies)
Discussion started by: dr_te_z
0 Replies

6. Shell Programming and Scripting

ksh program that finds the lowest number in a .txt file

i am having a problem finding the lowest number after punching in a bunch of numbers in the .txt file but its probably the way i have the code set up. help please! (4 Replies)
Discussion started by: tinsteer
4 Replies

7. Solaris

Resolving port number to program name

I was just checking to see if anyone had a script that would allow me to go from port number to program name. I tried to create my own script but it looks like it only works for IPv4 sockets and it looks like daemons such as sshd return as AF_INET6 (in pfiles) for some reason. I can fix my script... (0 Replies)
Discussion started by: thmnetwork
0 Replies

8. UNIX for Dummies Questions & Answers

Can you perfect my sed ?

I want to print only the lines that meet the criteria : "worde:" and "wordo;" I got this far: sed -n '/\(*\)\1e:\1o;/p;' But it doesn't quite work. Can someone please perfect it and tell me exactly how its a fixed version/what was wrong with mine? Thanks heaps, (1 Reply)
Discussion started by: maximus73
1 Replies

9. Shell Programming and Scripting

count number of entries perl program or Unix script

Hi I have a file with number of entries name 1 123 name 1 345 name 1 65346 name2 3243 name2 24234 name 2 234234 so on ......... how to count total number of entries for name 1 and name2...and so on Please guide. (1 Reply)
Discussion started by: manigrover
1 Replies

10. UNIX for Beginners Questions & Answers

How do I use grep to grab prime number output from my factor program?

I have a factor program that runs and outputs to stdout all the prime numbers that are specified in the given paramters, in this case 30000000-31000000. Command: factor/factor 30000000-31000000 Sample output: 30999979 = 30999979 30999980 = 2^2 5 11 140909 30999981 = 3 10333327... (6 Replies)
Discussion started by: steezuschrist96
6 Replies
test(1sh5)																test(1sh5)

Name
       test - condition evaluation command

Syntax
       test expr
       [ expr ]

Description
       The  command  evaluates the expression expr.  If the value of expr is true, the command returns a zero exit status; otherwise, it returns a
       nonzero exit status.  The command also returns a nonzero exit status if no arguments are specified.  The following primitives are  used	to
       construct expr:

       -r file	      True if file exists and is readable.

       -w file	      True if file exists and is writable.

       -x file	      True if file exists and is executable.

       -f file	      True if file exists and is a regular file.

       -d file	      True if file exists and is a directory.

       -c file	      True if file exists and is a character special file.

       -b file	      True if file exists and is a block special file.

       -p file	      True if file exists and is a named pipe (fifo).

       -u file	      True if file exists and its set-user-ID bit is set.

       -g file	      True if file exists and its set-group-ID bit is set.

       -k file	      True if file exists and its sticky bit is set.

       -s file	      True if file exists and has a size greater than zero.

       -t [ fildes ]  True if the open file whose file descriptor number is fildes (1 by default) is associated with a terminal device.

       -z s1	      True if the length of string s1 is zero.

       -n s1	      True if the length of the string s1 is non-zero.

       s1 = s2	      True if strings s1 and s2 are identical.

       s1 != s2       True if strings s1 and s2 are not identical.

       s1	      True if s1 is not the null string.

       n1 -eq n2      True  if	the integers n1 and n2 are algebraically equal.  Any of the comparisons -ne, -gt, -ge, -lt, and -le may be used in
		      place of -eq.

       These primitives can be combined with the following operators:

       !	      unary negation operator.

       -a	      binary and operator.

       -o	      binary or operator (-a has higher precedence than -o).

       ( expr )       parentheses for grouping.

       Note that all the operators and flags are separate arguments to the command.  Note also that parentheses are meaningful to  the	Shell  and
       must  be  escaped.   In the form of the command that uses square brackets ([]), instead of the word test, the brackets must be delimited by
       blanks.

See Also
       find(1), sh5(1), test(1)

																	test(1sh5)
All times are GMT -4. The time now is 02:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy