24 Computer -- Programming Concepts and Logics

WAP to input any number and display its factorial.

WAP to input any number and display its factorial.

The following is the source code to input any number and display its factorial:

#include <stdio.h>

#include <conio.h>


int main()

{

    int a, i, factorial;

    factorial = 1;

    printf("Input any number: ");

    scanf("%d", &a);

    

    if (a==0 || a==1) {

        printf("The factorial is 1");

        

    } else if (a<0) {

        for (i=a; i<0; ++i) {

        

        factorial *= i;

        }

    } else {

        for (i=a; i>0; --i) {

        

        factorial *= i;

        }

    }

    printf("The factorial of %d is %d.", a, factorial);

    

}




More questions on Programming Concepts and Logics

Close Open App