C program factorial using Array
How to Write Factorial Program With Array IN C language
void main()
{
int n;
clrscr();
printf("enter the value \n");
scanf("%d",&n) ;
printf("result=%ld",fact(&n)) ;
getch();
}
long int fact(int* a)
{
long int f=1,sum=0;
int i,j;
for(i=1;i<=*a;i++)
{
for(j=1;j<=i;j++)
{
f=f*i;
}
f=i/f;
sum=sum+f;
}
return sum;
}
How to Write Factorial Program With Array IN C language
void main()
{
int n;
clrscr();
printf("enter the value \n");
scanf("%d",&n) ;
printf("result=%ld",fact(&n)) ;
getch();
}
long int fact(int* a)
{
long int f=1,sum=0;
int i,j;
for(i=1;i<=*a;i++)
{
for(j=1;j<=i;j++)
{
f=f*i;
}
f=i/f;
sum=sum+f;
}
return sum;
}
0 comments: