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
Ad icon
ZTE MF283U 4G Unlocked Router (Used)
ayanthamaxi
Updated:
Sunday at 8:26 PM
ලංකාවේ හොඳම උපකාරක පන්ති සහ ගුරුවරුන් එකම තැනකින් - TopTuition.lk
dulithapathum
Updated:
Saturday at 8:07 AM
Colombo
RidhMathraa ’26 🎶✨
Tmadhusanka
Updated:
Wednesday at 11:58 PM
Ad icon
Colombo
PXN V10 Pro Direct Drive Racing Wheel (Under Warranty)
Abdur Rahman
Updated:
Wednesday at 10:23 PM
Ad icon
USDT ණය සේවාව - USDT Loan Service
පුරවැසියා
Updated:
Wednesday at 4:54 PM
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
Education
C/C++ Coding challenges
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: 8062527" data-attributes="member: 1293"><p>this can be done thru binomial theorem <img src="/styles/default/xenforo/smilies/default/P.gif" class="smilie" loading="lazy" alt=":P" title=":P :P" data-shortname=":P" /> but it uses more resources and it is slow for this usage. Thus I use some nifty algorithm workaround with some c++ STL. This is C++, so use an appropriate compiler; I recommend g++. <img src="/styles/default/xenforo/smilies/default/D.gif" class="smilie" loading="lazy" alt=":D" title="Big grin :D" data-shortname=":D" /><img src="/styles/default/xenforo/smilies/default/D.gif" class="smilie" loading="lazy" alt=":D" title="Big grin :D" data-shortname=":D" /> and oh it prints the triangle for 500 lines in a few seconds, do stress test this one.</p><p>[code]</p><p>#include <iostream></p><p>#include <vector></p><p>#define TYPE unsigned long int</p><p></p><p>using namespace std;</p><p>void pas(int n)</p><p>{</p><p> if (n>=1) cout<<"1\n"; else return;</p><p> if (n>=2) cout<<"1 1\n";</p><p> </p><p> vector<TYPE> *pv=new vector<TYPE>;</p><p> vector<TYPE> *pvw;</p><p> vector<TYPE>::iterator iter;</p><p> </p><p> TYPE i, tot;</p><p> </p><p> pv->push_back(1);</p><p> pv->push_back(1);</p><p> while (n>2){</p><p> pvw = new vector<TYPE>;</p><p> pvw->push_back(1);</p><p> iter=pv->begin();</p><p> i = *iter;</p><p> cout<<"1 ";</p><p> for (iter++; iter!=pv->end(); iter++){</p><p> tot = i + *iter;</p><p> i = *iter;</p><p> pvw->push_back(tot);</p><p> cout<<tot<<" ";</p><p> }</p><p> pvw->push_back(1);</p><p> cout<<"1\n";</p><p> delete pv;</p><p> pv = pvw;</p><p> n--;</p><p> }</p><p>}</p><p>int main()</p><p>{ int inp;</p><p> cout<<"How many levels of the pascal triangle do you want? ";</p><p> cin>>inp;</p><p> pas(inp);</p><p> return 0;</p><p>}</p><p>[/code]</p></blockquote><p></p>
[QUOTE="madurax86, post: 8062527, member: 1293"] this can be done thru binomial theorem :P but it uses more resources and it is slow for this usage. Thus I use some nifty algorithm workaround with some c++ STL. This is C++, so use an appropriate compiler; I recommend g++. :D:D and oh it prints the triangle for 500 lines in a few seconds, do stress test this one. [code] #include <iostream> #include <vector> #define TYPE unsigned long int using namespace std; void pas(int n) { if (n>=1) cout<<"1\n"; else return; if (n>=2) cout<<"1 1\n"; vector<TYPE> *pv=new vector<TYPE>; vector<TYPE> *pvw; vector<TYPE>::iterator iter; TYPE i, tot; pv->push_back(1); pv->push_back(1); while (n>2){ pvw = new vector<TYPE>; pvw->push_back(1); iter=pv->begin(); i = *iter; cout<<"1 "; for (iter++; iter!=pv->end(); iter++){ tot = i + *iter; i = *iter; pvw->push_back(tot); cout<<tot<<" "; } pvw->push_back(1); cout<<"1\n"; delete pv; pv = pvw; n--; } } int main() { int inp; cout<<"How many levels of the pascal triangle do you want? "; cin>>inp; pas(inp); return 0; } [/code] [/QUOTE]
Insert quotes…
Verification
Asuwa dahayen wadi kalama keeyada?
Post reply
Top
Bottom