Write a shell script that accept 7 numbers in loop

Write a shell script that accept 7 numbers in loop,then make a sum of this numbers. then count the numbers that are greater than 250 ?

Questions by angel rayan

Showing Answers 1 - 6 of 6 Answers

ardiansyah

  • Jul 5th, 2012
 

Code
  1. #!/bin/bash

  2. total=0

  3. c=0

  4. for a in {1..3};

  5.   do

  6.         echo -n "Write a number : "

  7.         read i

  8.         if [ $i -ge 250 ] ; then let "c=c+1"

  9.         fi

  10.         let "total = i + total"

  11.   done

  12. echo "total = $total"

  13. echo " > 250 = $c "

satish

  • Jul 10th, 2013
 

Code
  1.  

  2. total=0                                                                        

  3.                                                                                

  4. for a in 1 2 3 4 5 6 7                                                          

  5. do                                                                              

  6. echo "Enter number "$a                                                          

  7. read i                                                                          

  8. total=`expr $total + $i`                                                        

  9. done                                                                            

  10. echo $total

  11.  

  12. total=0                                                                        

  13.                                                                                

  14. for a in 1 2 3 4 5 6 7                                                          

  15. do                                                                              

  16. echo "Enter number "$a                                                          

  17. read i                                                                          

  18. total=`expr $total + $i`                                                        

  19. done                                                                            

  20. echo $total

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions