•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 373,565 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,852 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
This program generates lines of pascal's triangle, numbers after 23 generate weird output.
#include <iostream> #include <stdlib.h> using namespace std; string Separator(" "); float factorial (float n) { if (n == 0.0f) return 1.0f; else if (n != 1.0f) return n*factorial (n-1.0f); else return n; } float combination (float n,float r) { return factorial(r)/((factorial(r-n)*factorial(n))); } void printRow(float r) { for (float i=0.0f; i<=r; i+=1.0f){ cout << combination (i,r) << Separator; } } void printRows(float r) { for (float j=0.0f; j<r; j+=1.0f){ printRow(j); cout << endl; } } int main(int argc, char** argv) { float nRows = 10.0f; cout << "Hello, This is me Pascal. I'll give you "; if (argv [1] == 0) cout << "10 Lines of my famous triangle"; else if (atof (argv [1]) <= 0.0f) cout << "10 Lines of my famous triangle"; else { nRows = atof(argv [1]); cout << argv [1] << (nRows > 1? " Lines " : " Line ") << "of my famous triangle.\n"; } printRows(nRows); }
Comments (Newest First)
Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)