answersLogoWhite

0


Best Answer

echo "Enter a number: "

read num

i=2

res=1

if [ $num -ge 2 ]

then

while [ $i -le $num ]

do

res=`expr $res \* $i`

i=`expr $i + 1`

done

fi

echo "Factorial of $num = $res" v

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

Bash script to find factorial of a number

$ cat fact.sh

#!/bin/bash

if [ $# -ne 1 ]

then

echo "Usage: "

echo " $0 "

exit 1

fi

no=$1

fact=1

if [ $no -le 0 ]

then

echo "Please pass positive value."

exit 1

fi

while [ $no -ge 1 ]

do

let fact=fact*no

let no=no-1

done

echo "$1! = $fact"

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

clear

echo "Enter n"

read n

f=1

while [ $n -gt 0 ]

do

f=`expr $f \* $n`

n=`expr $n - 1`

done

echo "Factorial is " $f

Output :Enter n

5

Factorial is 120

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

#!/bin/sh

echo "Enter the number"

read num

factorial=1

for i in `seq 1 $num`

do

factorial=`expr $i \* $factorial`

done

echo $factorial

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

function fac() { [[ $1 < 2 ]] && echo $1 echo $(($1 * $(fac $(($1 - 1))))); }

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

#!/bin/bash
f=1
echo "The factorial is:"
for (( n=5;n>=1;n=n-1 ))
do
echo $f
(( f=f*n ))
done


This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a full program to find factors of given number in UNIX shell programming?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

One of two factors of a given number?

If the given number has two factors, one of them is 1.


How do you know a number if its factors are given?

There are two ways in which the factors can be given. You are given all the prime factors (and their multiplicity). In that case simply multiply them all together. Or You are given each factor. In this case, the biggest of these is the number.


Is the number of factors of a given number is limited?

Yes.


How many distinct strings of factors are there for a given number?

It varies with each given number.


What is the difference between program and programming?

define program i. program means set of instruction which are required for a particular type of task is called program ii. set of instruction or commands which are given for the computer to do different activity or jobs or works is called program define programming the process of creating/modifying a program; some people's job, others' hobby


How do you write a program to test if a given number is divisible by 6 in C programming?

if ( x % 6 == 0 ){ printf( "%d is divisible by 6", x ); } else { printf( "%d is not divisible by 6", x ); }


What is factors that appear in a complete list of factors for a given number only once?

distinct factors


Program in c language to find prime factors of a given number?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { int n,i; clrscr(); printf("Enter a Number:"); scanf("%d",&amp;n); printf("\n\nPrime Factors of %d is: ",n); for(i=2;i&lt;=n;i++) { if(n%i==0) { printf("%d,",i); n=n/i; i--; if(n==1) break; } } getche(); } this program will find the prime factors of a given numbe any assistance mail at :- devilllcreature@yahoo.com thank you


What is the difference between factors of a number and prime factors of a number?

All numbers have factors. Some factors are prime numbers. These are known as prime factors. The set of prime factors is a subset of the set of factors for any given number.


How do you find the number of its given factors?

You multiply the factors together. if the factors are 6 and 7 or 2,3 and 7, then the number is 6x7=2x3x7=42


What is called when factors that appear in a complete list of factors for given number only once?

distinct factors


Thw importance of ASP.net?

Object Oriented Programming is a subset of structured programming. After objects are created in a program, you use those objects and their methods to operate the program. In structured programming, you have a program with many methods in which you can use. One difference between structured programming and object-oriented programming is that structured programming uses the data that is given to them through parameters, while in object-oriented programming, the methods act upon the object's data (fields). This makes programming much easier because the fields are all there and you do not have to make sure that the correct field is passed to the correct method. All you have to do is call which field you want to work with.