🔒 Closed C language pa help

Status
Not open for further replies.
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
  • 509
    Views
  • 2
    Participants
Last reply from:
zacha

Trending Topics

Online now

Members online
1,078
Guests online
4,539
Total visitors
5,617

Forum statistics

Threads
2,354,200
Posts
29,382,635
Members
1,079,366
Latest member
Francis24
Back
Top