/* 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;
}
Pseudo code+factorial
factorial number Var num= prompt("enter any number "); Var i=1; Var fact=1; for(i=1;i
Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.
That's not the factorial of any number. For a start, the factorial of any number greater than or equal to 2 is even, because of the factor 2. The factorial of any number greater or equal to five ends with 0. Another answer: I suspect the questioner meant to ask how to write 8*7*6*5*4*3*2*1 as a factorial. If so, then the answer is "8!"
seq 1 2 99
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.
To write a program that calculates the factorial of a number in PHP, you can use a recursive function or an iterative approach. Here’s a simple example using a loop: function factorial($n) { $result = 1; for ($i = 2; $i <= $n; $i++) { $result *= $i; } return $result; } echo factorial(5); // Outputs: 120 This code defines a function that multiplies numbers from 2 up to the given number $n to compute the factorial.
Pseudo code+factorial
write a program to display your name age class schoolname e-mail 2hobby based on choice
int factorial(int n) { int i; int f=1; for(i=2;i<=n;++i) f*=i; return f; }
Write a program which takes any number of days from the user. the program should display the number of years, number of months formed by these days as well as the remaining days.
factorial number Var num= prompt("enter any number "); Var i=1; Var fact=1; for(i=1;i
Here's a simple C program to calculate the factorial of 10: #include <stdio.h> int main() { int i; unsigned long long factorial = 1; // Use unsigned long long for larger results for(i = 1; i <= 10; i++) { factorial *= i; } printf("Factorial of 10 is %llu\n", factorial); return 0; } This program uses a loop to multiply numbers from 1 to 10 and stores the result in factorial, which is then printed.
Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.
/*program to calculate factorial of a number*/ #include<stdio.h> #include<conio.h> void main() { long int n; int a=1; clrscr(); printf("enter the number="); scanf("%ld",&n); while(n>0) { a*=n; n--; } printf("the factorial is %ld",a); getch(); }
That's not the factorial of any number. For a start, the factorial of any number greater than or equal to 2 is even, because of the factor 2. The factorial of any number greater or equal to five ends with 0. Another answer: I suspect the questioner meant to ask how to write 8*7*6*5*4*3*2*1 as a factorial. If so, then the answer is "8!"
seq 1 2 99