-
Program in C to find 1 to n numbers of factorial
#include<stdio.h> #include<conio.h> int main() { long int f,i,j,n,n1; printf("Enter a number:-"); scanf("%d",&n1); for(i=1;i<=n1;i++) { n=i; f=1; j=1; while(j<=n) { f=f*j; j++; } printf("\nFactorial of %ld is %ld .",i,f); } getch(); }
Output:-
- Program in C to find 1 to nth numbers of factorial using function
#include<stdio.h> #include<conio.h> void Fact(int ); int main() { int n1; printf("Enter a number:-"); scanf("%d",&n1); Fact(n1); getch(); } void Fact(int x) { long int f,i,j,n; for(i=1;i<=x;i++) { n=i; f=1; j=1; while(j<=n) { f=f*j; j++; } printf("\nFactorial of %ld is %ld .",i,f); } }Output:-
0 Comments