![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| adding a 6 digit number retaining 0s on the left | kanchan_cp | Shell Programming and Scripting | 8 | 03-08-2007 09:58 AM |
| Extracting 10 digit number from txt files | c19h28O2 | Shell Programming and Scripting | 9 | 08-07-2006 06:06 PM |
| restrain the number of digits of a PID | mlefebvr | UNIX for Advanced & Expert Users | 1 | 05-27-2002 09:33 AM |
| Urgent!! How to write a shell program to execute command to access internet? | firebirdonfire | UNIX for Dummies Questions & Answers | 2 | 04-26-2001 11:16 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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..................
Last edited by banta; 10-29-2006 at 05:28 PM.. Reason: Wrong question |
|
||||
|
You need to initialise the variables num and sum
#!/bin/ksh a=12346 b=`expr length $a` echo " length : $b" typeset -i i=1 num=0 sum=0 while (( i <= $b )) do ((num=$(echo "${a}" | cut -c "${i}") )) if (( i == 1 )); then printf "$num" else printf "+$num" fi ((sum=sum + num)) ((i=i+2)) done printf "=${sum}\n" ~ Answer ------- length : 5 1+3+6=10 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|