#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    ミンダナオ、フィリピン
    Posts
    4
    Rep Power
    0

    Unhappy Help on Modified Arrays???


    Problem: Create a program that takes in two (2) integers from the user. These two integers will serve as the first two elements of your Fibonacci sequence. Store the first 20 elements in an array.

    Important: Use offset notation in accessing elements of your array.

    So far...I have this.

    Code:
    #include <stdio.h>
    
    int main()
    {
       int b[] = { 10, 20, 30, 40 }; 
       int num1;
       int num2;  
       int *bPtr = b;                
       int i;                        
       int offset;                   
    
      
       printf( "\nPointer/offset notation\n" );
      
       printf("Input first integer: ");
                     scanf("%d", &num1);
       printf("\nInput second integer: ");
                     scanf("%d",&num2);
    
       
    
    
       for ( offset = 0; offset < 4; offset++ ) {
          printf( "*( bPtr + %d ) = %d\n", offset, *( bPtr + offset ) );   
       } 
       system("pause");
       return 0;
    }
    I know it has wrongs I just have a mental block that I just...had to ask for a bits of help about this. I apologize for being so stupid;;;;;;;;;
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,376
    Rep Power
    1871
    Well you start with
    Code:
    // Store the first 20 elements in an array.
    int b[20] = { 0 };
    Then you have
    Code:
    // These two integers will serve as the first two elements of your Fibonacci sequence
    b[0] = num1;
    b[1] = num2;
    As for Fibonacci sequence, start with a web search for the algorithm.
    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

IMN logo majestic logo threadwatch logo seochat tools logo