Showing posts with label factorial. Show all posts
Showing posts with label factorial. Show all posts

Saturday, March 10, 2012

Write a program to find the factorial of a number using loop.

#include
#include
void main()
{
int a,b,fact=1;
clrscr();
printf("Enter number to find factorial");
scanf("%d",&b);
for(a=b;a>0;a--)
{
fact=fact*a;
}
printf("%d ",fact);
getch();
}

Write a C program to find the factorial of a number using recursion.

#include
#include
int fact(int);
void main()
{
int num,fact1;
printf("Enter a value of num");
scanf("%d",&num);
fact1=fact(num);
printf("factorial=%d",fact1);
getch();
}
int fact(int n)
{
int f=1;
if(n==0)
{
return 1;
}
else
{
f=n*fact(n-1);
return(f);
}
}

Tuesday, February 22, 2011

Write a Visual Basic program to print the factorial of any number

WAP to print the factorial of any number.
___________________________________

Private Sub Command1_Click()
a = Val(Text1.Text)
Call fact(a)
End Sub

Private Sub Command2_Click()
End
End Sub
Public Function fact(a)
If a = 0 Then
fact = 1
Text2.Text = fact
Else
fact = a * fact(a - 1)
Text2.Text = fact
End If
End Function

Private Sub Form_Load()

End Sub

_____________________________________
OUTPUT
_____________________________________


____________________________________
DOWNLOAD
____________________________________

Download its form

Download its Image