🔒 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
  • 504
    Views
  • 2
    Participants
Last reply from:
zacha

Trending Topics

Online now

Members online
719
Guests online
2,639
Total visitors
3,358

Forum statistics

Threads
2,331,984
Posts
29,261,667
Members
1,145,974
Latest member
jofre43
Back
Top