Our Blog Contain Detail about Some Technical Aspect like Programming, Blogger, Tools and Tip, Suggestion, Motivational, Health, Program in C and Java, Html

Write a program to calculate the factorial for given number using function.

 Write a program to calculate the factorial for given number using function.



Factorial for given number without using function

#include<stdio.h>
#include<conio.h>

void main()
{
     int i,n;
     int fact=1;
     printf("enter the number\n");
     scanf("%d",&n);
     for(i=n;i>=1;i--)
     {
          fact=fact*i;
     }
     printf("%d",fact);

}

Factorial for given number using function

#include<stdio.h>
#include<conio.h>
int fact(int num)
{

     int f=1,i;
     for(i=1;i<=num;i++)
     {
          f=f*i;
     }
     return f;
}

void main()
{
     int fa,n;
     printf("\n enter the number \n");
     scanf("%d",&n);
     fa=fact(n);
     printf("\n Factorial of number%d is %d",n,fa);
     getch();
}

Share:

No comments:

Post a Comment

Translate

Followers

Email Subscription

Enter your email address:

Delivered by FeedBurner

Recent Posts

Theme Support

Need our help to upload or customize this blogger template? Contact me with details about the theme customization you need.