Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Toyota Vitz scp10 For Sale
Lakmal Bandara
Updated:
Today at 10:50 AM
Ad icon
Cam ෂෝ කරන්න ආස කෙල්ලෝ
vip video seller srilanka
Updated:
Today at 2:17 AM
Cam show job
vip video seller srilanka
Updated:
Today at 2:01 AM
Vip විඩීයෝ තියේ හොරෙන් රෙකෝඩ් කරපුවා
vip video seller srilanka
Updated:
Today at 1:26 AM
Kandy
Welcome all my all new pet shop Bark.lk
dilumrane
Updated:
Monday at 12:26 PM
Electronics
Vehicles
Property
Search
Reply to thread
Forums
Computers & Internet
Tips & Tricks
nCr Engine(C++) + A joke
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="madurax86" data-source="post: 4064594" data-attributes="member: 1293"><p>Full code is below its not optimized for speed if you can post the optimizations that can be implemented, heres a <a href="http://1.bp.blogspot.com/_793N2ay-vhU/Sag6kAeuPDI/AAAAAAAAABQ/S7g3On38O8s/s1600/lol.JPG" target="_blank"><strong>LOL</strong></a> that i came across when i was coding this last night.</p><p></p><p>Any Problems comments are welcome; there are a lot of C programmers in EK if you can translate this to C <img src="/styles/default/xenforo/smilies/default/happy.gif" class="smilie" loading="lazy" alt=":)" title="Happy :)" data-shortname=":)" /> there are very few changes to be made ryt?</p><p>[CODE]</p><p>/*</p><p>factorial and nCr functions(not optimized)</p><p>==========================================</p><p>by madura.x86</p><p>comment: If you are getting minus values for a given nCr its because "long long"</p><p>type isnt enough try raising it to double, nothing wrong with the engine the </p><p>values get awfully longer when n goes just after 51, have fun with it but dont </p><p>just copy give credit where credit is due.</p><p>*/</p><p>#include <cstdlib></p><p>#include <iostream></p><p></p><p>using namespace std;</p><p>double fact(double i){</p><p> double j,k;</p><p> k=1;</p><p> for (j=1;j<=i;j++) k=k*j;</p><p> return k;</p><p> }</p><p>long long nCr(int n, int r){</p><p> int j,i,k,m1,n1;</p><p> long long p,q;</p><p> long long x[128],y[128];</p><p> if (r>n) return 0;</p><p> if (r==n) return 1;</p><p> if (r==0) return 1;</p><p> if (n<=2*r){</p><p> k=0;</p><p> for (j=n-r+1;j<=n;j++){</p><p> k++;</p><p> x[k]=j;</p><p> }</p><p> m1=k;</p><p> k=0;</p><p> for (i=2;i<=r;i++){</p><p> k++;</p><p> y[k]=i;</p><p> }</p><p> n1=k;</p><p> }</p><p> else</p><p> {</p><p> k=0;</p><p> for (j=r+1;j<=n;j++){</p><p> k++;</p><p> x[k]=j;</p><p> }</p><p> m1=k;</p><p> k=0;</p><p> for (i=2;i<=n-r;i++){</p><p> k++;</p><p> y[k]=i;</p><p> }</p><p> n1=k;</p><p> }</p><p> </p><p> for (j=1;j<=m1;j++)</p><p> for (i=1;i<=n1;i++){</p><p> if (x[j]%y[i]==0){ </p><p> x[j]=x[j]/y[i];</p><p> y[i]=1;}</p><p> </p><p> if (y[i]%x[j]==0){ </p><p> y[i]=y[i]/x[j];</p><p> x[j]=1;}</p><p> }</p><p> p=1;</p><p> q=1;</p><p> for (j=1;j<=m1;j++){</p><p> if (x[j]!=1) p=p*x[j];}</p><p> for (j=1;j<=n1;j++){</p><p> if (y[j]!=1) q=q*y[j];</p><p> }</p><p> return p/q;</p><p>}</p><p></p><p>int main(int argc, char *argv[]){</p><p> int i,j;</p><p> j=51;</p><p> for (i=0;i<j+1;i++){</p><p> cout<<j<<"C"<<i<<" = "<<nCr(j,i)<<endl;</p><p> }</p><p> </p><p> system("PAUSE");</p><p> return EXIT_SUCCESS;</p><p>}</p><p></p><p></p><p>[/CODE]</p></blockquote><p></p>
[QUOTE="madurax86, post: 4064594, member: 1293"] Full code is below its not optimized for speed if you can post the optimizations that can be implemented, heres a [URL="http://1.bp.blogspot.com/_793N2ay-vhU/Sag6kAeuPDI/AAAAAAAAABQ/S7g3On38O8s/s1600/lol.JPG"][B]LOL[/B][/URL] 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? [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; } [/CODE] [/QUOTE]
Insert quotes…
Verification
Awruddata maasa keeyada?
Post reply
Top
Bottom