Shell Script to Display the digits which are at odd positions in a given 5-digit number - The Coding Shala

Home >> Scripting >> Odd position digits

Shell Script to Display the digits which are at odd positions in a given 5-digit number

Display the digits which are at odd positions in a given 5-digit number.  



Example:

number is 23786

output - 276.

Code: 

#!/bin/bash
echo "enter 5 digit number"
read number
n=1
while((n<=5))
do
a=`echo $number | cut -c $n`
echo -n "$a"
n=`expr $n + 2`
done
echo " "



Other Posts You May Like
Please leave a comment below if you like this post or found some error, it will help me to improve my content.

Comments

Popular Posts from this Blog

Time Complexity, Space Complexity, Asymptotic Notations - The Coding Shala

Java Method Overloading - The Coding Shala

Shell Script to find sum, product and average of given numbers - The Coding Shala

Graph Representation using Adjacency Matrix - The Coding Shala

Find Second Smallest Element in the Array - The Coding Shala