C++ | Recursion, arrays and for loops

/ 26 Sept 2013 /
Look what I made :'), at first I couldn't be bothered, then I thought, wait, what if I can't do it, so I tried it, and it worked :'), but I only got up to a certain number of factorials, because I only used int, i'm guessing if I used a long or a long long, or even a double,(how ever that works) I could of done it, but yep, program4theday..





#include <iostream>
#include <ctime>
using namespace std;

int factorial(int x) {
 if(x==1) {
  return 1;
 } else {
  return x*factorial(x-1);
 }
}

int main() {
 
 int samir[31];
 
 cout << "Element - Value" << endl;
 int a = 0;
 for(int x = 1;x<=30;x++){
  a++;
  samir[x] = factorial(a);
  cout << endl << x << " = " << samir[x] << endl;
 }
 
}
 
Copyright © 2010 M(ath)+me, All rights reserved