The program goes as follows:
#include
#include
void main()
{
int i, j=1;
printf("Enter the value of the integer whose factorial has to be calculated");
scanf("%d",i);
while(j
i = i*(i-1);
i--;
printf("The factorial of the integer is:%d",i);
getch();
}
OTHER METHOD.............
#include
#include
void main()
{
int n,f;
f=1;
printf("Enter the number:\n");
scanf("%d",&n);
while(n>0)
{
printf("%d",n);
f=f*n;
n--;
}
printf("The factorial of the integer is:%d",f);
getch();
}
another method
A very easy method,,,,,,
these is the work of 2nd year high school programming........... CVHS..
#include
int main()
{
char m;
int ans, i, n;
i=0;
m='y';
while((m=='y')(m=='Y'))
{
cout<<"Input a number ";
cin>>n;
if(n==0)
{
ans=1;
cout<<"The factorial of a number is "< } else { ans=1; for(i=1;i<=n;i++) { ans=ans*i; } cout<<"The factorial of a number is "< } cout<<"\n Do you want to continue? (Y/N) "; cin>>m; } return 0; } see,, its very easy!!!! my new mathod #include #include main() { int i,j,div,mod; clrscr(); printf("enter any number = "); scanf("%d",&i); for(j=1;j<=i;j++) { mod=i%j; if(mod==0) { printf("%d*",j); div=i/j; i=div; j=1; } } if(j==i) { printf("%d",i); } getch(); }
#include <iostream> using namespace std; int main() { int i, number=0, factorial=1; // User input must be an integer number between 1 and 10 while(number<1 number>10) { cout << "Enter integer number (1-10) = "; cin >> number; } // Calculate the factorial with a FOR loop for(i=1; i<=number; i++) { factorial = factorial*i; } // Output result cout << "Factorial = " << factorial << endl;
In GW-BASIC, you can calculate the factorial of a number using a WHILE...WEND loop. First, initialize a variable for the factorial result (e.g., fact = 1) and a counter variable (e.g., i). Then, use a WHILE loop that continues as long as i is less than or equal to the number for which you want the factorial. Inside the loop, multiply fact by i, increment i, and finally print the result after the loop ends. Here's an example code snippet: INPUT "Enter a number: ", n fact = 1 i = 1 WHILE i <= n fact = fact * i i = i + 1 WEND PRINT "Factorial of "; n; " is "; fact
double factorial(double N){double total = 1;while (N > 1){total *= N;N--;}return total; // We are returning the value in variable title total//return factorial;}int main(){double myNumber = 0;cout > myNumber;cout
/* gcc -ansi -Wall -Wextra -pedantic -s -static 0.c -o 0 */ #include <stdio.h> int main ( ) { int n , factorial = 1 ; printf ( "enter the value of n\n") ; scanf ( "%i" , & n ) ; while ( n != 0 ) { factorial *= n ; n -- ; } printf ( "The factorial of n is\n%i\n" , factorial ) ; return 0; }
If you really wanted to do this, you could simulate multiplication with repeated addition.
To calculate the factorial of a number in a shell script, you can use a simple loop. Here's a basic example: #!/bin/bash factorial=1 read -p "Enter a number: " num for (( i=1; i<=num; i++ )) do factorial=$((factorial * i)) done echo "Factorial of $num is $factorial" This script prompts the user for a number, computes its factorial using a for loop, and then prints the result.
#include <iostream> using namespace std; int main() { int i, number=0, factorial=1; // User input must be an integer number between 1 and 10 while(number<1 number>10) { cout << "Enter integer number (1-10) = "; cin >> number; } // Calculate the factorial with a FOR loop for(i=1; i<=number; i++) { factorial = factorial*i; } // Output result cout << "Factorial = " << factorial << endl;
To calculate the factorial of a given number in C on a Unix system, you can use a simple recursive or iterative function. Here's an example of an iterative approach: #include <stdio.h> unsigned long long factorial(int n) { unsigned long long result = 1; for (int i = 1; i <= n; i++) { result *= i; } return result; } int main() { int number; printf("Enter a positive integer: "); scanf("%d", &number); printf("Factorial of %d is %llu\n", number, factorial(number)); return 0; } Compile the code using gcc filename.c -o factorial and run it with ./factorial to calculate the factorial of a number.
In GW-BASIC, you can calculate the factorial of a number using a WHILE...WEND loop. First, initialize a variable for the factorial result (e.g., fact = 1) and a counter variable (e.g., i). Then, use a WHILE loop that continues as long as i is less than or equal to the number for which you want the factorial. Inside the loop, multiply fact by i, increment i, and finally print the result after the loop ends. Here's an example code snippet: INPUT "Enter a number: ", n fact = 1 i = 1 WHILE i <= n fact = fact * i i = i + 1 WEND PRINT "Factorial of "; n; " is "; fact
Here's a simple Java program to find the factorial of a given number using a recursive method: import java.util.Scanner; public class Factorial { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter a number: "); int number = scanner.nextInt(); System.out.println("Factorial of " + number + " is " + factorial(number)); } static int factorial(int n) { return (n == 0) ? 1 : n * factorial(n - 1); } } This program prompts the user for a number and calculates its factorial recursively.
double factorial(double N){double total = 1;while (N > 1){total *= N;N--;}return total; // We are returning the value in variable title total//return factorial;}int main(){double myNumber = 0;cout > myNumber;cout
In Prolog, a simple factorial program can be defined using recursion. Here's a basic implementation: factorial(0, 1). % Base case: factorial of 0 is 1 factorial(N, Result) :- N > 0, N1 is N - 1, factorial(N1, Result1), Result is N * Result1. % Recursive case You can query the factorial of a number by calling factorial(N, Result). where N is the number you want to compute the factorial for.
kjhk
chutia mc,bc bhosdika
(4 times 4 factorial + 4) divided by 4 4 factorial + the square root of 4 minus (4 divided by 4)
In a C program that calculates the factorial of a number using a function, the program typically prompts the user for an integer input. The function then recursively or iteratively computes the factorial by multiplying the number by the factorial of the number minus one until it reaches one. For example, if the user inputs 5, the program outputs 120, as 5! = 5 × 4 × 3 × 2 × 1. The final result is displayed on the screen.
no answer....pls post