That’s it and have a nice week.
flickr photo by Daniel Hoherd
https://www.flickr.com/photos/warzauwynn/2794764081/
Some Rights Reserved
The code i wrote is this: https://github.com/sabaldaba/TC101/blob/master/Wsq09-Factorial
The program at the end also gives you the option of doing another operation or to end, this was done thanks to a while loop while the factorial calculator was done with a for loop since in there i knew a specific range.
Hope you like it!
]]>
Factorials are one of the most fascinating parts of math, but I for one couldn’t wrap my head around how to do a code for this one. Credit to my partner Samantha Rivera for showing me an easy way to do it through recursion. I’ll try and do it with a loop in a future edit.
Enjoy the link! WSQ 9.
]]>Also with a video on Youtube: https://www.youtube.com/watch?v=6cTP_ls_DLY
Here is my code: https://github.com/Andreandc/TC1017/blob/master/WSQ09
]]>// Factorial Calculator
#include <iostream>
using namespace std;
int fact (int q, int e, int w) {
q = 0;
w = 1;
cout << “Dame un número positivo ” <<endl;
cin >> e;
while (q<e) {
w = w*(q+1);
q = q+1;}
cout <<“El factorial de ” << e << ” es “;
return w;}
int main () {
char t=’y’;
int x;
int y;
int z;
while (t==’y’) {
cout << fact (x,y,z) <<endl <<endl;
cout <<“Si desea calcular otro factorial, teclee y ” << endl;
cout <<“Si no lo desea, teclee n ” << endl;
cin >> t;}
if (t==’n’){
cout <<“Que tenga un excelente y extraordinario día ” <<endl;}
else
{cout <<“Sólo puedes teclear la letra ‘y’ o la letra ‘n’ ” <<endl;
cout <<“Por favor vuelva a correr el programa”<<endl;}
return 0;}
And here’s the test run:
]]>