Full code is below its not optimized for speed if you can post the optimizations that can be implemented, heres a LOL that i came across when i was coding this last night.
Any Problems comments are welcome; there are a lot of C programmers in EK if you can translate this to C
there are very few changes to be made ryt?
Any Problems comments are welcome; there are a lot of C programmers in EK if you can translate this to C
there are very few changes to be made ryt?
Code:
/*
factorial and nCr functions(not optimized)
==========================================
by madura.x86
comment: If you are getting minus values for a given nCr its because "long long"
type isnt enough try raising it to double, nothing wrong with the engine the
values get awfully longer when n goes just after 51, have fun with it but dont
just copy give credit where credit is due.
*/
#include <cstdlib>
#include <iostream>
using namespace std;
double fact(double i){
double j,k;
k=1;
for (j=1;j<=i;j++) k=k*j;
return k;
}
long long nCr(int n, int r){
int j,i,k,m1,n1;
long long p,q;
long long x[128],y[128];
if (r>n) return 0;
if (r==n) return 1;
if (r==0) return 1;
if (n<=2*r){
k=0;
for (j=n-r+1;j<=n;j++){
k++;
x[k]=j;
}
m1=k;
k=0;
for (i=2;i<=r;i++){
k++;
y[k]=i;
}
n1=k;
}
else
{
k=0;
for (j=r+1;j<=n;j++){
k++;
x[k]=j;
}
m1=k;
k=0;
for (i=2;i<=n-r;i++){
k++;
y[k]=i;
}
n1=k;
}
for (j=1;j<=m1;j++)
for (i=1;i<=n1;i++){
if (x[j]%y[i]==0){
x[j]=x[j]/y[i];
y[i]=1;}
if (y[i]%x[j]==0){
y[i]=y[i]/x[j];
x[j]=1;}
}
p=1;
q=1;
for (j=1;j<=m1;j++){
if (x[j]!=1) p=p*x[j];}
for (j=1;j<=n1;j++){
if (y[j]!=1) q=q*y[j];
}
return p/q;
}
int main(int argc, char *argv[]){
int i,j;
j=51;
for (i=0;i<j+1;i++){
cout<<j<<"C"<<i<<" = "<<nCr(j,i)<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
Last edited:

all numbers will be char arrays 
.