What's new

Help C language pa help

zacha

Forum Veteran
Established
1653360366880.png
1653360407562.png
 

Attachments

Solution
C:
#include <stdio.h>

int main()
{
    int n,o;
    unsigned long factorial=1;

    printf("Enter an integer: ");
    scanf("%d", &n);
    o = n;

    if (n < 0)
    {
        printf("Invalid number!");
    }
    else
    {
        while (n > 0)
        {
            factorial = factorial * n;
            n = n - 1;
        }

        printf("\n%d! = %lu", o, factorial);
    }

    getch();
    return 0;
}
C:
#include <stdio.h>

int main()
{
    int n,o;
    unsigned long factorial=1;

    printf("Enter an integer: ");
    scanf("%d", &n);
    o = n;

    if (n < 0)
    {
        printf("Invalid number!");
    }
    else
    {
        while (n > 0)
        {
            factorial = factorial * n;
            n = n - 1;
        }

        printf("\n%d! = %lu", o, factorial);
    }

    getch();
    return 0;
}
 
Solution

Similar threads

Back
Top