If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > unix help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-14-06, 11:48
nyst8fmind nyst8fmind is offline
Registered User
 
Join Date: Oct 2006
Posts: 6
unix help

if anybody can help with this please

write a simple script. is working properly.
Look at the following examples:
Example 1:
[min@alpha min]$ ./lastname
Enter an integer number:
3
You entered 3

The sum of all the integers from 0 to 3 is 6
The integer 3 that you entered is odd

Example 2:
[min@alpha min]$ ./lastname
Enter an integer number:
4
You entered 4

The sum of all the integers from 0 to 4 is 10
The integer 4 that you entered is even
Note: Your lastname script must do 3 things:
1) Display which integer the user has entered. For example, if the user enters 3 then lastname script says "You entered 3"
2) If the user enters an integer. For example, 3 then 1+2+3=6, 4 1+2+3+4=10, or 100 1+2+3+...+100=5050.
the script will have to identify if the user input integer is odd or even and display accordingly. For example, if the user enters 3 it should display "The integer 3 that you entered is odd" or if the user enters 4 it should display "The integer 4 that you entered is odd
Reply With Quote
  #2 (permalink)  
Old 11-14-06, 14:27
Tyveleyn Tyveleyn is offline
Registered User
 
Join Date: Aug 2006
Location: The Netherlands
Posts: 248
I don't get it, everything you need to know is here shell script help!!!...
Reply With Quote
  #3 (permalink)  
Old 11-14-06, 14:33
nyst8fmind nyst8fmind is offline
Registered User
 
Join Date: Oct 2006
Posts: 6
hey!

i got it to say the number i put, and to figure out the odd and the even, i just need the addition between 0 and the integer i input i just the formula.
Reply With Quote
  #4 (permalink)  
Old 11-15-06, 02:07
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
Code:
i=4  # Read from input
oddeven[0]='even'
oddeven[1]='odd'
echo "The integer $i is ${oddeven[$(($i%2))]} and the sum is $(($i*($i+1)/2))"
Formula: http://mathworld.wolfram.com/Sum.html

Last edited by pdreyer; 11-15-06 at 02:10.
Reply With Quote
  #5 (permalink)  
Old 11-15-06, 14:32
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Cool

Quote:
Originally Posted by nyst8fmind
i got it to say the number i put, and to figure out the odd and the even, i just need the addition between 0 and the integer i input i just the formula.

Try this formula:
Code:
((sum = n * (n + 1) / 2))


__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On