answersLogoWhite

0

function fact(int n); ans = n * fact(n-1); endfunction

User Avatar

Wiki User

16y ago

What else can I help you with?

Related Questions

What is a program in c to calculate factorial of number?

First of all we will define what factorial is and how to it is calculated.Factional is non negative integer. Notation would be n! It is calculated by multiplying all integers from 1 to n;For example:5! = 1 x 2 x 3 x 4 x 5 = 120.Note: 0! = 1Small C program that illustrates how factorial might be counted:#include int factorial(int num);int main() {int num;printf("Enter number: ");scanf("%d", &num);printf("Factorial: %d\n", factorial(num));return 0;}int factorial(int num) {if (num == 0) {return 1;}return num * factorial(num - 1);}Testing:Enter number: 5Factorial: 120Enter number: 0Factorial: 1


How many numbers of n digits exist if the sum of all digits is s?

I've been trying to figure this out myself for a discrete structure class.From the digging I've done online I've found this formula thus far:if n is the number of digits, and s is the sum:C(n+s-1 , n-1) where C denotes "choose" as in C(n , k) "n choose k" which can be solved by(n! / [ (n-k)! * k! ] )this seems to work for situations where the sum is < 10, or so claims the forum I found.I whipped it all up into a scheme function if anyone wants to take advantage:;;factorial: num -> num;;finds factorial of num.(define (factorial num)(if (or (= num 1) (= num 0))1(* num (factorial (sub1 num)))));;==========================;;xchy: num num -> num;;the "n choose k" function(define (xchy n k)(/ (factorial n)(* (factorial(- n k))(factorial k))));;==========================;;n-dig&sum-s: num num -> num;;finds the number of n digit combinations with sum s;;C(n+s-1,n-1)(define (n-dig&sum-s n s)(xchy (sub1 (+ n s))(sub1 n)))


How do you write a full program to find factors of given number in UNIX shell programming?

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


Factorial in c program using for loop?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { int i,n,fact=1; clrscr(); printf("enter the number"); scanf("%d",&amp;n); for(i=1;i&lt;=n;i++) printf("%d",n); fact=fact*i; { printf("the factorial is=%d",fact); } getch(); } By:-Abhishek Goyal(goyal.abhi40@yahoo.com)


What is a factorial function in Visual Basic?

' Iterative solution Function iterativeFactorial(ByVal n As Long) As Long Dim factorial As Long = 1 For i As Long = 1 To n factorial *= i Next Return factorial End Function ' Recursive solution Function recursiveFactorial(ByVal n As Long) As Long If n &lt;= 1 Then Return n End If Return n * recursiveFactorial(n - 1) End Function


Write a program in C to find the factoial of 5?

/* gcc -ansi -Wall -Wextra -pedantic -s -static 0.c -o 0 */ #include &lt;stdio.h&gt; int main ( ) { int n = 5 , factorial = 1 ; while ( n != 0 ) { factorial *= n ; n -- ; } printf ( "%i\n" , factorial ) ; return 0; }


Write a C-like program fragment that calculate the factorial function for argment 12 with do while loop?

#!/usr/bin/perl print factorial($ARGV[11]); sub factorial { my($num) = @_; if($num == 1) { return 1; # stop at 1, factorial doesn't multiply times zero } else { return $num * factorial($num - 1); # call factorial function recursively } }


Mini project in c language with coding?

C Program to find factorial of a numberSimple C Programint main() {int n,i,f=1;printf("enter any num \n");scanf("%d",&n);for(i=1;i


Abap Program To find Factorial of number?

report zbharath. data:num type i value 5, fac type i value 0. perform fact using num changing fac. write:/ 'factorial of',num,'is',fac. form fact. using value(f-num) type i. changing f-fact type i. f-fact=1. while f-num ge 1. f-fact=f-fact*f-num. f-num=f-num-1. endwhile. endform.


How do you write a program that calculate factorial in javascript?

factorial number Var num= prompt(&quot;enter any number &quot;); Var i=1; Var fact=1; for(i=1;i


How do you wrte ac programe for factorial?

#include &lt;stdio.h&gt; int main() { int fact=1,num; printf("Enter number: "); scanf("%d",&amp;num); if((num==0) (num==1)) { printf("Factorial = %d",fact); return 0; } else { while(num!=1) { fact=fact*num; num--; } printf("Factorial = %d",fact); return 0; } }


C program to find factorial of a no?

this is a code for calculating it recursivelly: float Factorial (float n) { if (n&lt;=1) return 1.0; else return n* Factorial(n-1); }