How to use find out the factorial of a number in C language

program to use find out the factorial of a number in C language


#include <stdio.h>
long int factorial(int n);
int main()
{
    int num;
    printf("Enter a number : ");
    scanf("%d",&num);
    if(num<0)
    printf("No factorial of negative number\n");
    else 
    printf("Factorial of %d is %ld\n",num,factorial(num));
    return 0;
} 
long int factorial(int n)
{
    int i;
    long int fact=1;
    if(n==0){
           return 1;
    }
    for(i=n; i>1; i--){
        fact*=i;
    }
    
    
    return fact;
}

output


Enter a number : 8
Factorial of 8 is 40320

How to use whether a number is even or odd in C language

program to use whether a number is even or odd in C language


#include <stdio.h>
void find(int n);
int main()
{
    int num;
    printf("Enter a number : ");
    scanf("%d",&num);
    find(num);
    return 0;
}
void find (int n)
{
    if(n%2==0)
    printf("%d is even\n",n);
    else
    printf("%d is odd\n",n);
}

output


Enter a number : 444
444 is even

How to use function find the sum of two numbers in C language

program to use function find the sum of two numbers in C language


#include <stdio.h>
int sum(int x,int y)
{
    int s;
    s=x+y;
    return s;
}
int main()
{
    int a,b,s;
    printf("Enter value for a and b : ");
    scanf("%d %d",&a,&b);
    s=sum(a,b);
    printf("sum of %d and %d is %d\n",a,b,s);
    return 0;
}

output


Enter value for a and b : 12
6
sum of 12 and 6 is 18

How to use find the sum of two numbers in C Language


#include <stdio.h>
int sum(int x, int y) /*function definition*/
{
    int s;
    s = x + y;
    rextturn s;
}
int main(void)
{
    int a, b, s;
    printf("Enter values for a and b : ");
    scanf("%d %d", &a, &b);
    s = sum(a, b); /*function call*/
    printf("Sum of %d and %d is %d\n", a, b, s);
    return 0;
}

Output


Enter value for a and b :12
6
Sum of 12 and 6 is 18