What's new

C language

zacha

Forum Veteran
Established
Joined
Sep 5, 2021
Posts
782
Reaction
56
Points
691
1653982545213.png


1653982551551.png
 

Attachments

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;
}

It looks familiar, paki check kung gagana yung code.
 
salamat papsss
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;
}

It looks familiar, paki check kung gagana yung code.
 
#include <stdio.h> int main() { int num1,prod; printf("enter number \n"); scanf("%d",&num1); int num2 = num1; if(num1<0){ printf("%d! = Invalid",num2); }else{ for(int i=num1-1; i>=1; i--){ prod = num1*i; num1 = prod; } printf("%d! = %d",num2,num1); } return 0; }

yan mas maliit ung lines and gumamit ng for loop
 
Last edited:

Similar threads

Back
Top