answersLogoWhite

0

echo enter n value

read n

sumodd=0

sumeven=0

i=0

while [ $i -ne $n ]

do

echo "Enter Number"

read num

if [ `expr $num % 2` -ne 0 ]

then

sumodd=`expr $sumodd + $num`

sumeven=`expr $sumeven+$num`

fi

i=`expr $i + 1`

done

echo Sum of odd numbers = $sumodd

echo Sum of even numbers = $sumeven

User Avatar

Wiki User

13y ago

What else can I help you with?

Continue Learning about Engineering

Write a shell program to check and display 10 leap years?

dono


Write a program in shell script to display odd number from 0 to 100?

seq 1 2 99


When might it be necessary or advisable to write a shell script instead of a shell function?

A shell function will do nothing unless it is explicitly called by other code, typically in a shell script. A shell script is a runnable, executable process, which can call other shell scripts and/or functions. The question might be worded backwards - it is necessary to write shell functions for shell scripts when certain logical functionality is required to be performed multiple times. Consider a shell function equivalent to a program subroutine - they operate the same way.


What command should be given to compile a C program from the command prompt?

You need a compiler. Gcc or g++ can be run from a unix shell, or a windows implementation of one like cygwin.


How do you write a Shell script to find the greatest among the given set of numbers using command line arguments?

To find the greatest number among a set of numbers provided as command line arguments in a Shell script, you can use a loop to iterate through the arguments. Here's a simple example: #!/bin/bash greatest=$1 for num in "$@"; do if (( num > greatest )); then greatest=$num fi done echo "The greatest number is: $greatest" Save this script as find_greatest.sh, make it executable with chmod +x find_greatest.sh, and run it by passing numbers as arguments, like ./find_greatest.sh 3 5 1 8.

Related Questions

Shell program for gcd of three given numbers?

write a shell program for finding out gcd of three given numbers? write a shell program for finding out gcd of three given numbers? write a shell program for finding out gcd of three given numbers? check bellow link http://bashscript.blogspot.com/2009/08/gcd-of-more-than-two-numbers.html


Write a Shell program to find the smallest number from a set of numbers?

k


Shell program to generate the prime numbers betwee 1 to 50?

2,3,5,7,9,11,13,17,19,23,29,31,37,39,41,43,47,49


Shell program to find the smallest digit of a given number?

syntax error


Unix script to calculate average of n numbers given by user?

You really don't want to do this in a shell script - scripting languages in Unix typically do not handle or work with floating values, only integers. A better way would be to write a program to do this that works under Unix, such as a 'C" program. See the related link for an example


Write a shell program to check and display 10 leap years?

dono


Write a Shell program to find the sum of cube of individual digits of a number?

no thanks


Shell script to find LCM of the given two numbers?

Shell program to find LCM and hcf of two no.s tput clear echo "Enter first no" read a echo "Enter 2nd no" read b p= 'expr $a \* $b' while [$b -ne 0] do r= 'expr $a % $b' a=$b b=$r done LCM = 'expr $p / $a' echo "LCM = $LCM" echo "Hcf = $a"


Write a shell program to delete all the files in the current directory?

in winxp del *.* /Q /S


Shell script to find amstrong numbers within a given range?

Check below link


Write a program in shell script to display odd number from 0 to 100?

seq 1 2 99


Write a shell program called whos to display a sorted list of the logged in usersJust display the user names and no other information?

The 'users' command should do that; you don't need to write a shell script to get that information in that format.