Computer Science, asked by Aaryan102604, 1 year ago

hi any Java programmer here can you tell me the answer without using scanner class or only the syntax please see do not answer if you do not know the answer thanks


Write a program to calculate factorial of a number​

Answers

Answered by hemamahindrakar
2

To understand this example, you should have the knowledge of following C programming topics:

C Programming Data Types

C Programming Operators

C if...else Statement

C Programming for Loop

The factorial of a positive number n is given by:

factorial of n (n!) = 1*2*3*4....n

The factorial of a negative number doesn't exist. And, the factorial of 0 is 1, 0! = 1

Example: Factorial of a Number

#include <stdio.h>

int main()

{

int n, i;

unsigned long long factorial = 1;

printf("Enter an integer: ");

scanf("%d",&n);

// show error if the user enters a negative integer

if (n < 0)

printf("Error! Factorial of a negative number doesn't exist.");

else

{

for(i=1; i<=n; ++i)

{

factorial *= i; // factorial = factorial*i;

}

printf("Factorial of %d = %llu", n, factorial);

}

return 0;

}

Output

Enter an integer: 10

Factorial of 10 = 3628800

This program takes a positive integer from the user and computes factorial using for loop.


hemamahindrakar: to kb??
Aaryan102604: Adnnnn krke ek user h... wo uska bhai h... aur mjhe follow bji krta hai.... wo dekh lega toh aafat ho jayego
hemamahindrakar: ohhh
hemamahindrakar: xD...
hemamahindrakar: lol..
Aaryan102604: hmmm:-(
Aaryan102604: T_T
hemamahindrakar: so sad dude☹️☹️
Aaryan102604: hmm
hemamahindrakar: its okk dude kuch nahi hota... itna bhi sad mat ho...
Similar questions