Thread: Extra number?

  1. #1
    Registered User
    Join Date
    Sep 2008

    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?

    #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
    Join Date
    Dec 2007
    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, 01:10 PM