Thread: doubt

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    3

    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
    thnx in advance...

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Consider this

    123 / 10 = 12
    123 % 10 = 3
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    3
    Quote Originally Posted by Salem View Post
    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
    Last edited by archit1993; 12-26-2011 at 05:39 AM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Dec 2011
    Posts
    3
    yeah it was pascals triangle till 14641 line.....how will we do it?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Doubt
    By sureshsuresh528 in forum C Programming
    Replies: 3
    Last Post: 02-01-2008, 03:00 AM
  2. doubt...
    By anntenna333 in forum C Programming
    Replies: 4
    Last Post: 04-27-2006, 11:35 AM
  3. doubt
    By spveer in forum C Programming
    Replies: 3
    Last Post: 08-15-2005, 02:23 AM
  4. When in doubt, run away
    By Zach L. in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 11-07-2004, 10:32 AM
  5. Doubt
    By ansi_1999 in forum C Programming
    Replies: 5
    Last Post: 05-05-2004, 08:49 AM