🔒 Closed C language

Status
Not open for further replies.

zacha

Forum Veteran
1653982545213.webp


1653982551551.webp
 
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
 
Status
Not open for further replies.

About this Thread

  • 4
    Replies
  • 291
    Views
  • 3
    Participants
Last reply from:
zacha

Online now

Members online
459
Guests online
1,268
Total visitors
1,727

Forum statistics

Threads
2,277,853
Posts
28,979,294
Members
1,229,112
Latest member
rosearugay
Back
Top