๐Ÿ”’ 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
  • 444
    Views
  • 2
    Participants
Last reply from:
zacha

Online now

Members online
845
Guests online
953
Total visitors
1,798

Forum statistics

Threads
2,276,096
Posts
28,967,579
Members
1,231,118
Latest member
czardinas
Back
Top