# doubt

• 12-26-2011
archit1993
doubt
i want a code such that i can be able to access each digit of a number.
eg..
in a for loop in 1 iteration,i want to access digits of 11^2ie 121 and in next iteration digits of 11^3 ie 1331 and in next 11^4 etc
i want to access 1,2 and 1 separately in 121.....

if we have 121 stored in an int variable,how can we transfer its value to an array?

i mean..

int k;
int a[10];
now i want vlue of k(121) to go into a such that a[0]=1,a[1]=2 and a[2]=1....and the value of k keeps changing in d loop,so i want corresponding change in a[]....

hope u get my point
• 12-26-2011
Salem
Consider this

123 / 10 = 12
123 % 10 = 3
• 12-26-2011
archit1993
Quote:

Originally Posted by Salem
Consider this

123 / 10 = 12
123 % 10 = 3

but the program is not limited to a 3 digit number.
actually, i want to write a code for output:

....1
...1 1
..1 2 1
.1 3 3 1
1 4 6 4 1

the dots represent spaces(spaces were not coming,it was becoming left indented so i put dots)
these r powers of 11,with alternate space & digits
• 12-26-2011
Salem
Is it really powers of 11, or Pascal's Triangle?
Pascal's triangle - Wikipedia, the free encyclopedia

Because strictly powers of 11 breaks down after a few rows.
• 12-26-2011
archit1993
yeah it was pascals triangle till 14641 line.....how will we do it?
• 12-26-2011
Salem
Well "we" could try reading the algorithm description on wikipedia, then attempt some code to calculate the current row based on the previous row.

Eg.
Code:

```int oldRow[10] = { 1 }; int newRow[10] = { 0 };  // make this contain { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 }```
Then with some more iterations of the code.
Code:

```int oldRow[10] = { 1, 3, 3, 1 }; int newRow[10] = { 0 };  // make this contain { 1, 4, 6, 4, 1, 0, 0, 0, 0, 0 }```
I mean, once you have the algorithm in place, and an initialised row to work from, the rest is pretty easy.