Thread: Array Help!

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    28

    Array Help!

    Hi I am doing a basic assignment dealing with arrays. When I call to the fourth element in the array which is 12.0 and try to display it, it prints 0.

    I don't see what I am doing wrong. Here is my code:

    Code:
    #include <stdio.h>
    
    double x[ ] = { 16.0, 12.0, 6.0, 8.0, 12.0, 14.0, 14.0, -54.5 };
    
    int i = 2;
    
    int main(void)
    {
      printf("%d %.lf\n", 4, x[4]);
      printf("%d %.lf\n", i, x[i]);
      printf("%.lf\n", x[i] + 1);
    
    }
    This is my output:

    4 0
    2 0
    0

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Looks OK to me, but you probably want to use
    Code:
    %.1lf
    (that's a number one before the lower-case L)

  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    28
    Thank you good sir. It seems that I have forgotten the difference between 1 and l

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 09-09-2012, 02:29 PM
  2. Replies: 2
    Last Post: 03-20-2012, 08:41 AM
  3. Replies: 9
    Last Post: 08-23-2010, 02:31 PM
  4. Replies: 9
    Last Post: 04-07-2010, 10:03 PM
  5. Replies: 6
    Last Post: 11-09-2006, 03:28 AM