FOR NO'S TILL 8 ONLY Example for Number 4
4!=4*3*2*1 which is = 24
MOV R1,#04
MOV R0,#04
MOV A,R0
CALL:DEC R0
MOV F0,R0
MUL AB
DJNZ R1,CALL
LCALL 0003
SHARAD KOTHARKAR
Source program :
LXI SP, 27FFH ; Initialize stack pointer
LDA 2200H ; Get the number
CPI 02H ; Check if number is greater than 1
JC LAST
MVI D, 00H ; Load number as a result
MOV E, A
DCR A
MOV C,A ; Load counter one less than number
CALL FACTO ; Call subroutine FACTO
XCHG ; Get the result in HL
SHLD 2201H ; Store result in the memory
JMP END
LAST: LXI H, 000lH ; Store result = 01
END: SHLD 2201H
HLT
Subroutine Program:
FACTO:LXI H, 0000H
MOV B, C ; Load counter
BACK: DAD D
DCR B
JNZ BACK ; Multiply by successive addition
XCHG ; Store result in DE
DCR C ; Decrement counter
CNZ FACTO ; Call subroutine FACTO
RET ; Return to main program
INCLUDE Irvine32.inc
.data
num DWORD ?
fact DWORD 1
str1 DB "Enter a number to Calculate Factorial: ",0
str2 DB "The Factorial is: ",0
.code
main PROC
call clrscr
mov edx,OFFSET str1
call WriteString
call ReadDec
mov num,eax
mov ecx,num
L1 :
mov eax,ecx
mov ebx,fact
mul ebx
mov fact,ebx
LOOP L1
mov edx,OFFSET str2
call WriteString
mov eax,fact
call WriteDec
exit
main ENDP
END main
#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;
Pseudo code+factorial
since factorial is for example , the factorial of 5 = 5 (5-1)(5-2)(5-3)(5-4) that means the last number to subtract from 5 is 4 , which is (n-1) ie the factorial of any number is (n-0)(.............)(n-(n-1)) to write this , 5 REM to calculate the factorial of any number 6 DIM fac AS INTEGER LET fac = 1 10 INPUT "enter the number to find its factorial "; a ' variable a 15 FOR b = 0 TO (a-1) 'numbers that will be subtracted from the " a" 20 c= a -b 'each number in the factorial calculation 25 fac = fac * c 'to compute each multiplication in the factorial 30 NEXT b 35 PRINT 'to leave a line 40 PRINT fac 45 END note this due to some unattained raesons works for numbers 0 to 7
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.
function factorial(n) { var x=1; while(n>1) x*=(n--); return x; }
int factorial(int n) { int i; int f=1; for(i=2;i<=n;++i) f*=i; return f; }
#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;
Pseudo code+factorial
since factorial is for example , the factorial of 5 = 5 (5-1)(5-2)(5-3)(5-4) that means the last number to subtract from 5 is 4 , which is (n-1) ie the factorial of any number is (n-0)(.............)(n-(n-1)) to write this , 5 REM to calculate the factorial of any number 6 DIM fac AS INTEGER LET fac = 1 10 INPUT "enter the number to find its factorial "; a ' variable a 15 FOR b = 0 TO (a-1) 'numbers that will be subtracted from the " a" 20 c= a -b 'each number in the factorial calculation 25 fac = fac * c 'to compute each multiplication in the factorial 30 NEXT b 35 PRINT 'to leave a line 40 PRINT fac 45 END note this due to some unattained raesons works for numbers 0 to 7
nr\m;laeoh9y0m g.qthnedxc In fortran: do i=1,5 write(6,*)i enddo stop end This program will write the numbers 1 to 5 on the screen.
Write a c program to compute the surface area and volume of a cube
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(); }
function factorial(n) { var x=1; while(n>1) x*=(n--); return x; }
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!"
I turn on my computer and when Windows has loaded I start Code::Blocks. Code::Blocks is an IDE that I use with Mingw. In Code::Blocks I start a new project and add a source file. I type my program in the window with the flashing cursor. How do you write a program, it looks to me that the way you do it is to plagiarize someones work and call it your own. When you do your exams you will look really.
{A program to compute the area of a triangle} {by Ogboin W. Meshach} Var; b,h:real; BEGIN Writeln('Triangle'); Write('Base: '); Readln(base); Write('Height: '); Readln(height); area:=0.5*base*height; Writeln('Area: ', area :0:2); End.