🔒 Closed C language pa help

Status
Not open for further replies.

zacha

Forum Veteran
1653360366880.webp
1653360407562.webp
 
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
Status
Not open for further replies.

About this Thread

  • 2
    Replies
  • 474
    Views
  • 2
    Participants
Last reply from:
zacha

Trending Topics

Online now

Members online
1,090
Guests online
1,741
Total visitors
2,831

Forum statistics

Threads
2,286,534
Posts
29,038,466
Members
1,217,040
Latest member
DevilOil
Back
Top