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
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"
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
#!/bin/sh
echo "Enter the number"
read num
factorial=1
for i in `seq 1 $num`
do
factorial=`expr $i \* $factorial`
done
echo $factorial
function fac() { [[ $1 < 2 ]] && echo $1 echo $(($1 * $(fac $(($1 - 1))))); }
#!/bin/bash
f=1
echo "The factorial is:"
for (( n=5;n>=1;n=n-1 ))
do
echo $f
(( f=f*n ))
done
If the given number has two factors, one of them is 1.
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.
Yes.
It varies with each given number.
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
if ( x % 6 == 0 ){ printf( "%d is divisible by 6", x ); } else { printf( "%d is not divisible by 6", x ); }
distinct factors
#include<stdio.h> #include<conio.h> void main() { int n,i; clrscr(); printf("Enter a Number:"); scanf("%d",&n); printf("\n\nPrime Factors of %d is: ",n); for(i=2;i<=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
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.
You multiply the factors together. if the factors are 6 and 7 or 2,3 and 7, then the number is 6x7=2x3x7=42
distinct factors
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.