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
In order to write a program, we have to have an algorithm. In this case, we can use two temporary variables to store up the sums: evenSum = 0 oddSum = 0 for i = 0 to array.size do: if isEven(i): evenSum = evenSum + array[i] else: oddSum = oddSum + array[i]
#include<stdio.h>
main()
{
int a,b,sum;
print f("enter two numbers");
scan f("%d%d",&a&b);
sum=a+b
print f(the sum of a and b is %d,sum);
}
== == #include<stdio.h> #include<conio.h> void main() { int a,b,c; clrscr(); a=20,b=30; c=a+b; printf("the sum of two number is %d",c); getch(); }/*the program is closed here*/ output of the program is the sum of two numbers is 50
/*C program to find the entered number is even of odd*/ #include #include void main() { int n; clrscr(); printf("Enter the number\n"); scanf("%d",&n); if((n%2)==0) printf("%d is even number",n); else printf("%d is odd number",n); getch(); }
public void sumEvenOdd(int[] input)
{
int sumEven = 0;
int sumOdd = 0;
for (int i = 0; i < input.length; i++)
{
if (input[i] % 2 == 0)
{
sumEven = sumEven + input[i];
}
else
{
sumOdd = sumOdd + input[i];
}
}
//Do what you want here to sumEven and sumOdd like printing it.
}
int t=27; // assuming youre looking for the first 27 even numbers
int n=1; int s=0;
while(n<=t){
s=s+(n*2);
n++;
}
printf("%dn", s);
dono
seq 1 2 99
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.
You need a compiler. Gcc or g++ can be run from a unix shell, or a windows implementation of one like cygwin.
yes
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
k
2,3,5,7,9,11,13,17,19,23,29,31,37,39,41,43,47,49
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
syntax error
dono
no thanks
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"
in winxp del *.* /Q /S
Check below link
seq 1 2 99
The 'users' command should do that; you don't need to write a shell script to get that information in that format.