Help mathematical shell programming

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Help mathematical shell programming
# 1  
Old 11-13-2012
Help mathematical shell programming

Hello Guys,For my homework I must write a shell script to do this serie,


ImageI know that I must use the "bc" for that, but for the script's itself i have no idea,(beginner)


Can you plz just help me for have some idea?
Thanks


I wrote a program baut it does not work,
Code:
#!/bin/sh
echo "Input number"
read n
counter=0
ans=1
while [ $counter -ne $n ]
do
    ans=`expr 4*(-1/(2*$counter+1))`| bc -l 
    counter=`expr counter+1`
done

echo "the sum of the series is :-$ans"

any suggestion could help me a lot

Thanks

Last edited by fpmurphy; 11-13-2012 at 07:34 PM..
# 2  
Old 11-13-2012
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Mathematical calculations using shell

Dear All, I read some variables in a file and assigned as name for each of them. If I do echo I am able to see the values as 1.0E-05,3.4,5.0E-03 etc, Now I want to do some mathematical operations with them. Lets say 1 1.0E-05*5.0E-03 expected ans is 5.0E-08 2 1.0E-05/5.0E-03 expected... (9 Replies)
Discussion started by: linuxUser_
9 Replies

2. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

3. Shell Programming and Scripting

Shell programming

Hi every one,i am new to unix.Can any one tell me about shell programming.. (1 Reply)
Discussion started by: martina100011
1 Replies

4. Shell Programming and Scripting

Mathematical functions in bash shell

Hi, How can i do the mathematical calculations in bash shell? Are the mathematical functions available in bash shell? Ex: pow ceil floor sqrt (5 Replies)
Discussion started by: cola
5 Replies

5. Shell Programming and Scripting

Needs help on shell programming

Hi guys, I need some help to create a script or command :rolleyes: I do not have much experience in shell programming :confused: I have a file with the lines below on 10000 lines: 12.06.09/14:20:13 4 sms/s 12.06.09/14:20:16 4 sms/s 12.06.09/14:20:17 3 sms/s 12.06.09/14:20:18 3... (5 Replies)
Discussion started by: julienp
5 Replies

6. Shell Programming and Scripting

shell script receiving variable and doing mathematical function

Hello, Please help for the following scenario: 1. Shell Scipt should receive 2 variables values (say a and b). 2. Within shell script, there should be division of those numbers (a/b). 3. The result should be whole number i.e. in case the result comes out to be 9.4, it should be returned as... (3 Replies)
Discussion started by: damansingh
3 Replies

7. Shell Programming and Scripting

need help for shell programming

My purpose was to print out all of name of students in a list.First of all,I created a file name "List" in /home/tuan/Desktop/Shell_programming as below Tom Henry Ben Linda Marry And my script "script" is #!/bin/sh path=/home/tuan/Desktop/Shell_programming/List for student in $path... (3 Replies)
Discussion started by: thungmail
3 Replies

8. Shell Programming and Scripting

Shell programming

Hi, Iam new to shell program, I want to check a file which is having same lines 2 times and i want to display it in a seperate file. File format is : AQWERTYU|1234567890 ASDFGHJK|0987654321 ZXCVBNML|1098576453 AQWERTYU|1234567890 I need to take the 1st and 4th lines in the above... (5 Replies)
Discussion started by: nivas
5 Replies

9. Shell Programming and Scripting

Shell Programming

Provides a menu structure that allows a user to select several options - input a name and address, lookup a name and address, delete a name and address, and print a formatted report from a text database (note: this requirement assumes that you will use the program to create a database, though in... (1 Reply)
Discussion started by: DonOmar
1 Replies

10. Shell Programming and Scripting

shell programming

I want notes for learning Shell programming (2 Replies)
Discussion started by: Neha Agarwal
2 Replies
Login or Register to Ask a Question