i hav thiught a lot about the problem but at the end i was not even able to mave an inch forword .the problem is: we hav to develop a program that make user input a series and then will calculate the misiong term.


ex:

1>4,6,9, ,14,16,19,...
then the answer should be 11

2>1,2,7,16,29,46,?,...
then it should return 67

First figure out the algorithm on paper, then code it.

I hope you know that it's impossible in general case. For example, an user might type 1st countings of his Geiger sensor;). It's a series too...

Sounds to me like he needs to elaborate more on exactly what the assignment wants, unless there's a magic algorithm out there that can predict the readings of geiger counters. The two series he showed are pretty easy, but are they the only ones?

The Shadow knows.

Exactly!

they r not the only ones there can be any series(integer).

Well , Abhi According to the Question That You are asking. You need the computer to determine the a sequence from user input. This is not definable as the user may type in anything . If thats not the case and you are given an arithmetic progression when 2 numbers are given and told to find the next sequence. Then you can take the difference between the 2 numbers and then go on adding it.

Ok, there are two type of number succesions:

1. Arithmetic: When a number is added constantly. 2, 6, 10, 14, 18, 22

Here the rule is +2 after every term.

2. Geometric: When a number is multiplied constantly. 4, 8, 16, 32, 64, 128, 256

Here the rule is *2 after every term.


Find the algorithm by using this formula:

1. For Arithmetic succesions: (An - A1) - (n-1)

2. For Geometric succesions: Sqrt"n-1"(An/A1)

For these formulas to work you need to have the user introduce the first term, and the last term.

Hope this helps. :)

Edit:

I re-read your problem and you could solve it using this mind-set:

Have the program use the first term as A1 and the second term as An and use the appropiate formula to find the rule of the succesion. The it's a matter of simply using the rule on the first term "n" number of times the users requests.

Let me know how it goes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.