On a side note I forgot but if you know n ahead of time you can just simple do
int n = 3;
int factorial = n * (n-1) * (n-2);
However, that only works if you know n ahead of time and you can change the factorial variable according to n.
WAIT I CAN'T USE LOOPS AND I'M CONFUSED COULD SOMEONE CODE THIS FOR ME PLEASEEE I WILL LOVE YOU FOREVER
;;myfact.rkt
(define myfact
(lambda (n)
(cond ((zero? n)
1)
(else (* n (myfact (- n 1)))))))
>[This is just a start, because I don't have racket loaded, and had to go from memory]
>John (gnujohn)
Hi, I'm a computer science student in High School taking Intro to CS1. I need help coding a factorial such that n! = n* (n-1) * (n-2) * ....1, except I cannot use the primitive (factorial a) and I must use a conditional.
I am a beginner, my language is Beginner Student and I know basic primitives, Boolean operators, conditionals/if statements, but that's it.
I cannot come up with a way to solve this problem! Please help me!! My attempt is below, but I didn't get too far. :(