0% found this document useful (0 votes)
7 views2 pages

OS File

The document contains programs for swapping two numbers, checking even or odd numbers, calculating factorial of a number, and printing fibonacci series. It shows the code and output for each program.

Uploaded by

Sameer Najam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

OS File

The document contains programs for swapping two numbers, checking even or odd numbers, calculating factorial of a number, and printing fibonacci series. It shows the code and output for each program.

Uploaded by

Sameer Najam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

$ echo "Program for swapping two numbers: "

Program for swapping two numbers:

~$ a=2

~$ b=3

~$ c=$a

~$ a=$b

~$ b=$c

~$ echo "Numbers after swapping: "

Numbers after swapping:

~$ echo "a= $a"

a= 3

~$ echo "b= $b"

b= 2

$ echo "Program for even odd numbers :"

Program for even odd numbers :

$ read n

28

~$ if [ $((n % 2)) -eq 0 ];

>then echo "$n is even";

> else echo "$n is odd";

>fi

28 is even
echo " Program for factorial :"

Program for factorial :

~$ num=7

~$ factorial=1

~$ counter=$num

~$ while [[ $counter -gt 0 ]] ;

>do factorial=$(($factorial * $counter));

> counter=$(($counter-1)); done

~$ echo "factorial=$factorial"

factorial=5040

~$ echo "Progeam for fibonacci series :"

Progeam for fibonacci series :

~$ a=1

~$ b=2

~$ n=7

~$ for (( i=0; i<n; i++ )); do echo -n "$a ";

> fn=$((a + b)); a=$b; b=$fn; done

1 2 3 5 8 13 21

You might also like