In C++:
#include <iostream>
using namespace std;
int fact(int x);
int main()
{
int x, total;
cout << "Enter a number: ";
cin >> x;
total = fact(x);
cout << "The factorial of " << x << " is: " << total << endl;
char wait;
cin >> wait;
return 0;
}
int fact(int x)
{
if(x == 1)
{
return 1;
}
return fact(x - 1) * x;
}
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.
#!/usr/bin/perl print factorial($ARGV[11]); sub factorial { my($num) = @_; if($num == 1) { return 1; # stop at 1, factorial doesn't multiply times zero } else { return $num * factorial($num - 1); # call factorial function recursively } }
Pseudo code+factorial
factorial number Var num= prompt("enter any number "); Var i=1; Var fact=1; for(i=1;i
write a lex program to delete space from the program
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.
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.
int factorial(int n) { int i; int f=1; for(i=2;i<=n;++i) f*=i; return f; }
#!/usr/bin/perl print factorial($ARGV[11]); sub factorial { my($num) = @_; if($num == 1) { return 1; # stop at 1, factorial doesn't multiply times zero } else { return $num * factorial($num - 1); # call factorial function recursively } }
Pseudo code+factorial
factorial number Var num= prompt("enter any number "); Var i=1; Var fact=1; for(i=1;i
write a java program to find factorial using recursive and non recursive
int main (void) { puts ("18826771768889260997437677024916008575954036487149242588759823150835\ 31563316135988668829328894959231336464054459300577406301619193413805\ 97818883457558547055524326375565007131770880000000000000000000000000\ 000000"); return 0; }
write a lex program to delete space from the program
write an assembly language program to find sum of N numbers
The simplest way is probably to read the numbers into an array and then prints each element of the array starting at the last one and moving backwards.
720