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
Pure VPN - Up to 27 Months
vgp
Updated:
Today at 8:10 AM
එක පැකේජ් එකයි මාසෙටම Unlimited Internet. තාමත් DATA CARD දාන්න සල්ලි වියදම් කරනවද? අඩුම මිලට අපෙන්.
sayuru bandara
Updated:
Tuesday at 12:30 PM
Ad icon
ඉන්ටර්නෙට් එකෙන් හරියටම සල්ලි හොයන්න සහ Success වෙන්න කැමතිද? 🚀 (E-Money & Success Stories)
siri sumana
Updated:
Saturday at 11:44 PM
Gemini AI PRO 18 months Offer
Hawaka
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
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
Hath warak paha keeyada? (hatha wadikireema paha)
Post reply
Top
Bottom