Logo 
Search:

Unix / Linux / Ubuntu Articles

Submit Article
Home » Articles » Unix / Linux / Ubuntu » Homework HelpRSS Feeds

Write a shell program to find the sum of the series sum=1+1/2+...+1/n

Posted By: Meryl Schmidt     Category: Unix / Linux / Ubuntu     Views: 18749

Write a shell program to find the sum of the series sum=1+1/2+...+1/n

Code for Write a shell program to find the sum of the series sum=1+1/2+...+1/n in Unix / Linux / Ubuntu

echo Enter a number
read n
i=1
sum=0
while [ $i -le $n ]
do
sum=`expr $sum + \( 10000 / $i \)`
i=`expr $i + 1`
done
echo Sum n series is
i=1
while [ $i -le 5 ]
do
a=`echo $sum | cut -c $i`
echo -e "$a\c"if [ $i -eq 1 ]
then
echo -e ".\c"
fi
i=`expr $i + 1`
done
echo
  
Share: 



Meryl Schmidt
Meryl Schmidt author of Write a shell program to find the sum of the series sum=1+1/2+...+1/n is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!