C Saved Program: quiescent-dog

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


#include <stdio.h>
int main()
{
    int n,i,r;
    int factorial = 1,factorial1=1,factorial2=1;
    printf("Enter an integer: \n");
    scanf("%d",&n);
        scanf("%d",&r);

printf("%d%d",n,r);
    // show error if the user enters a negative integer
    //if(n>0||r>0){
    if (n > 0){

        for(i=1; i<=n; ++i)
        {
            factorial *= i;              // factorial = factorial*i;
        }
        printf("Factorial of %d = %d", n, factorial);
    }

 if (r > 0){
            for(i=r-1; i>0; i-2)
        {
        for(i=1; i<=r; ++i)
        {
            factorial1*=i;              // factorial = factorial*i;
        }
        printf("Factorial of %d = %d", r, factorial1);
    }
     
 }
    if (n> 0||r>0){
            
        for(i=1; i<=(n-r); ++i)
        {
            factorial2*=i;              // factorial = factorial*i;
        }
        printf("Factorial of %d = %d", r, factorial2);
    }


    return 0;
}

    
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs