| | |
c++ query
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2007
Posts: 5
Reputation:
Solved Threads: 0
i have tried to do the pascals law in the following method .....bt i m not getting a triangle shape.could someone help me out in this tight Spot?? here is the code what i have typed...
c Syntax (Toggle Plain Text)
#include<iostream.h> #include<conio.h> #include<iomanip.h> long TRIANGLE(int x,int y); int main() { clrscr(); int lines=0,n; cout<<"enter how many lines"; cin>>n; for(lines=0;lines<=n;lines++) { for(int i=0;i<lines;i++) for(int j=0;j<lines-n;j++) cout<<setw(2)<<" "; for(j=0;j<=i;j++) cout<<setw(4)<< TRIANGLE(i,j); cout<<endl; } getch(); } long TRIANGLE(int x,int y) {if(x<0||y<0||y>x) return 0; long c=1; for (int i=1;i<=y;i++,x--) c=c*x/i; return c; }
Last edited by Ancient Dragon; Dec 31st, 2007 at 5:57 pm. Reason: add code tags
•
•
Join Date: Jul 2005
Posts: 1,678
Reputation:
Solved Threads: 263
First, remember to post code surrounded by code tags to retain indentation to make the code easier to read.
Assuming you want the peak of the triangle centered over the base then I would would calculate the numbers and put them into a container printing the container once all calcualtions were done and not print the numbers to the screen on the fly. I'd consider using nested loops to control the display of the triangle using leading spaces followed by visible values followed by trailing spaces (though the trailing spaces are more conceptual than real).
How many spaces will be needed will depend on how many lines are displayed, how many characters will be needed in the display of the last line, and how many digits there are in the largest number contained within the triangle.
Assuming you want the peak of the triangle centered over the base then I would would calculate the numbers and put them into a container printing the container once all calcualtions were done and not print the numbers to the screen on the fly. I'd consider using nested loops to control the display of the triangle using leading spaces followed by visible values followed by trailing spaces (though the trailing spaces are more conceptual than real).
How many spaces will be needed will depend on how many lines are displayed, how many characters will be needed in the display of the last line, and how many digits there are in the largest number contained within the triangle.
Hey raniajay, you'd be happy that C++ has provided standard libraries without the .h extension since long. You can simply write
C++ Syntax (Toggle Plain Text)
#include <iostream>
"You know you're a computer geek when you try to shoo a fly away from the monitor screen with your cursor. That just happened to me. It was scary." - Juuso Heimonen.
"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
![]() |
Similar Threads
- Sql Query (VB.NET)
- Removing Query Strings (ASP.NET)
- Double MySQL Query (PHP)
- Dynamic Query (JSP)
- MySQL nested query / joined query conversion help (MySQL)
- problem with lengthy query (Java)
- Retreiving variables from a sql query into a form (PHP)
- Query Building (Database Design)
Other Threads in the C++ Forum
- Previous Thread: convert int to hexadecimal
- Next Thread: Calling SocketServer's constructor
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






