1. ## pas triangle problem...

Hi it's me again now i have another problem i can't figure out what's wrong with my code.. It work's well with lower numbers like 4, 5 but above five the triangle is messed up need help here's the code..I can't get what's wrong with my code????.....

Code:
```#include <iostream>

using namespace std;
int main()
{
int n;
cout << "Input num\n";
cin >> n;
cin.ignore();
for (int y = 0; y < n; y++)
{
int k = 1;

cout.width(n-y);
for (int x = 0; x <= y; x++)
{
cout << k << " ";
k = k * (y - x) / (x + 1);

}
cout << "\n";
}
cout << "\n";

cin.get();
}```
tnx...

2. Each digit of a number is a character in the output, so a two digit number will take up two digits instead of one. That is why your output looks funny (I assume that's your problem since the code works fine otherwise for me).

I think the output is fine the way it is, but if you want to change it, you'll have to figure out how many characters the largest value will be and make sure each value printed uses that many characters. For example, for a starting point of 5, the largest value is 10. When you print out the one-digit numbers, they should all be "01" or " 1" so that they all take up two characters.

3. Code:
```#include<iostream>
using namespace std;
typedef unsigned int uint;
int main(){
uint pos[2]={0,0},ar[200][200];
while(pos[0]<1 || pos[1]>pos[0]|| pos[1] <1){
cout<<"row: ";
cin>>pos[0];
cout<<"column: ";
cin>>pos[1];
}

for(int i =0 ; i<pos[0];i++) ar[i][0]=ar[i][i]=1;

for(uint i=2;i<=pos[0];i++)
for(uint j=1;j<i;j++)
ar[i][j]=ar[i-1][j]+ar[i-1][j-1];

cout<<ar[pos[0]-1][pos[1]-1]<<endl;

cin.get();cin.get();

return 0;
}```

4. ahhhh okey understood tnx for the hints guys i really appreciate it

5. Originally Posted by Daved
Each digit of a number is a character in the output, so a two digit number will take up two digits instead of one. That is why your output looks funny (I assume that's your problem since the code works fine otherwise for me).

I think the output is fine the way it is, but if you want to change it, you'll have to figure out how many characters the largest value will be and make sure each value printed uses that many characters. For example, for a starting point of 5, the largest value is 10. When you print out the one-digit numbers, they should all be "01" or " 1" so that they all take up two characters.
Btw how can i take up two characters like you said "01" instead of 1 how can i do that 01 thing...... tnx....and sorry for being such a noob....

6. There are different ways. You could just figure out how many digits the number has and add the 0's manually. Or you could use io manipulators and functions like width() to set the appropriate size of the output to the same number of digits each time and perhaps setfill to make sure it fills the extras with 0's. Try playing around with those ideas to see if you can figure out a way.

7. Thank you very much