guys pls help me to creat a progam using array that will display the ff sequence
1,1,2,3,5,8,13,21,3,55
after displaying the fibonacci series tha program will ask for an array psition & will display its corresponding value this is done continnously...

please...

Dani AI

Generated

asked for an array-based Fibonacci generator that shows the series and then repeatedly returns the value at a requested position. The sequence in Post #1 has a likely typo ("21,3,55" should be "21,34,55"). encouraged showing effort and reminded about knowing the series; the short plan below follows that advice and includes compact C and Python examples plus important cautions.

Algorithm (compact): decide how many terms N to store; allocate an array/list of size N; set first two terms to 1 and 1; fill the rest with a[i] = a[i-1] + a[i-2]; print the array; then loop reading a position (use a sentinel like 0 to exit), validate the index (1-based vs 0-based), and print the corresponding array element.

Sample C (uses long long, checks overflow, interactive position queries):

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int main(void) {
    int N = 50;
    long long *a = malloc(sizeof(long long) * N);
    if (!a) return 1;
    a[0] = 1; a[1] = 1;
    int count = 2;
    for (int i = 2; i < N; ++i) {
        if (a[i-1] > LLONG_MAX - a[i-2]) break;
        a[i] = a[i-1] + a[i-2];
        ++count;
    }
    for (int i = 0; i < count; ++i) printf("%lld%s", a[i], (i+1==count)?"\n":",");
    while (1) {
        long pos;
        printf("Position (1-%d, 0 to exit): ", count);
        if (scanf("%ld", &pos) != 1 || pos == 0) break;
        if (pos < 1 || pos > count) printf("Out of range\n");
        else printf("%lld\n", a[pos-1]);
    }
    free(a);
    return 0;
}

Sample Python (arbitrary precision, interactive):

N = 100
a = [1, 1]
while len(a) < N:
    a.append(a[-1] + a[-2])
print(','.join(map(str, a)))
while True:
    try:
        pos = int(input("Position (1-{}, 0 to exit): ".format(len(a))))
    except (ValueError, EOFError):
        break
    if pos == 0:
        break
    if 1 <= pos <= len(a):
        print(a[pos-1])
    else:
        print("Out of range")

Notes: arrays in C are 0-based (adjust for 1-based position queries); signed 32-bit int overflows around F(47) (safe up to F(46)), signed 64-bit up to F(92); Python integers grow arbitrarily. Use bounds checks and a sentinel to stop the interactive loop.

Recommended Answers

All 2 Replies

Just pleading someone for help won't help...show some effort on your part as well...

First think how you can generate the series...then the array part will be very easy...

Develop an algorithm (a plan of action on how you would build the series) and post it...we can help you from there...:)

First of all you know about the fibonacci series........
After that try to implement the code for that......

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.