Extra number?

This is a discussion on Extra number? within the C Programming forums, part of the General Programming Boards category; When I run this program, the first number that is printed is some odd number like 134508085, why does it ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    58

    Extra number?

    When I run this program, the first number that is printed is some odd number like 134508085, why does it print that first instead of the number I input first?

    Code:
    #include <stdio.h>
    
    int main( int argc, char *argv[] ){
    
      int a[10];
      int i;
    
      printf("Enter ten numbers: \n");
    
      for(i = 0; i < 10; i++){
        printf("%d> ", i+1);
        scanf("%d", &a[i]);
      }
    
      for(;i >=0; i--)  
        printf("%d \n", a[i]);  
    
      return 0;
    }

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,639
    When you hit the second for loop, i == 10, which is outside of the bounds of your array.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help getting program print out the digit in words
    By cosmiccomputing in forum C Programming
    Replies: 26
    Last Post: 04-24-2008, 08:28 AM
  2. Need help with this compiler error
    By Evangeline in forum C Programming
    Replies: 7
    Last Post: 04-05-2008, 09:27 AM
  3. Calculating next prime number
    By anilemon in forum C Programming
    Replies: 8
    Last Post: 04-17-2006, 10:38 AM
  4. Prime number program problem
    By Guti14 in forum C Programming
    Replies: 11
    Last Post: 08-06-2004, 04:25 AM
  5. parsing a number
    By juancardenas in forum C Programming
    Replies: 1
    Last Post: 02-19-2003, 12:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21