• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

how to get this output

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

can anybody help me how to get this output
thanks in advance
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like a homework question. We would like to help, but you have to demonstrate that you have made an attempt at a solution yourself. Do you have any code so far that you can show us?

Regards,
JD
 
Ranch Hand
Posts: 904
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok..

Let's look at the output.

The output tells us, that:

1) You need a loop.
2) Something is being added

Does this help?

/Svend Rost

Edit: Was to "friendly"...
[ February 22, 2006: Message edited by: Svend Rost ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you familiar with loop syntax? This "for" syntax is very common. If you don't know this bit, look up "for" in a language reference.

Try this and see what it prints.

Computer geeks often count from zero like this, because in assembly language we often count the distance from the start of a list. The first entry is zero steps away from the begining.

See if you can change that loop to print 1 through 5 instead of 0 through 9. Show us what you make! Sharing is the fun part. Then think about how that's going to help with your assignment.
[ February 22, 2006: Message edited by: Stan James ]
 
Loveleen Saroya
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i got the output but was looking if there is any other way to do it.. like making a part string and then reverse and concat.
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First note that 11*11 = 121, 111*111=12321, etcetera.

Then that 10^n - 1 is a number that consists of n 9's, so (10^n - 1)/9 consists of n 1's.

So therefore we get:
 
Loveleen Saroya
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks joni
 
Loveleen Saroya
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Joni
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

First note that 11*11 = 121, 111*111=12321, etcetera.


That's clever
But that may not be the purpose of the assignment.
The person asking for this kind of output probably expects his students to use loops, not one liner mathematical trics (That may come as a shock if he did not realize this himself)
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Heh heh, I'd bet the instructor is looking for loops and turn in both solutions for sure. Was it Bernoulli who got in trouble as a child ... A teacher told the class to add all the numbers from 1 to 100 just to kill time, and one bright student realized it's 1+100 + 2+99 ... or 101*50 pairs. Blew the afternoon nap.

Oh, you were way ahead of me on loops. I might try to build both ends of the string at the same time in a single inner loop:

[ February 23, 2006: Message edited by: Stan James ]
 
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it was Leibnitz who found the sum-formula... :-)
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic