(i). to find the factorial of a given integer
(a).without using recursive function.
#include(stdio.h) // place this '<' & '>' instead of '(' & ')' before stdio.h
#include(conio.h)
int fact( int); // function declaration
int main( )
{
int no,result;
clrscr( );
printf("Enter the required number:");
scanf("%d", &no);
result = fact( no);
printf("\n %d Factorial is : %d", no, result);
getch( );
return 0;
}
int fact(int n)
{
int ft,
for( ft=1; n>=1; n--)
ft=ft*n;
return ft;
}
Output:- 4 Factorial is : 24
(a).using recursive function.
#include(stdio.h) // place this '<' & '>' instead of '(' & ')' before stdio.h
#include(conio.h)
int fact( int); // function declaration
int main( )
{
int no,result;
clrscr( );
printf("Enter the required number:");
scanf("%d", &no);
result = fact( no);
printf("\n %d Factorial is : %d", no, result);
getch( );
return 0;
}
int fact(int n)
{
int ft,
if( n==1)
return 1;
else
ft= n*fact (n-1);
return ft;
}
Output:- 4 Factorial is : 24
Subscribe to:
Post Comments (Atom)
I want c program for display a pyramid like
ReplyDelete---------1
-------1 2 3
-----1 2 3 4 5
---1 2 3 4 5 6 7
-1 2 3 4 5 6 7 8 9
I F you got sent to
My mail-id: gthazhaikumar@gmail.com
i want c program to be printed like this
ReplyDelete-99999999999
--999999999
---9999999
---999999
----9999
-----99
------9
PLZ very urgent