Thread: Array problem. Can you find the problem with this?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    25

    Array problem. Can you find the problem with this?

    Hi guys

    this is what I want the program to do:

    it's to save up to 100 given number>0 from keyboard in some Array. If the given number is smaller than 0, it should stop and give back all the numbers inserted up to then, but backwards. so it gives out all the numbers saved in the array from the last typed number to the first one.

    this is my idea which apparently doesn't work. and I can't see the reason..I'd be thankful for any hint


    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void) {
        int i;
    
     int number [100]={};  //"number" is just a name for the array
    
    
       printf("give a number!\n");
    
    
        scanf("%d",&i);
    
         while(i>0){
    
     number[100] = i;    //saves the number in the array?
    
             getchar();
    
    
             if(i<0)
    
                break;
             }
    
    
      printf("%d",number[--i]);
    
                 putchar('\n');
    
        
         return EXIT_SUCCESS;
    }
    Last edited by Aitra; 01-01-2013 at 06:46 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can't seem to find the problem, help.
    By JoeyJoe in forum C Programming
    Replies: 8
    Last Post: 03-04-2011, 02:03 PM
  2. help me to find the problem
    By behzad_shabani in forum C Programming
    Replies: 3
    Last Post: 06-12-2008, 01:17 AM
  3. pls help i cant find the problem :(((
    By condorx in forum C Programming
    Replies: 3
    Last Post: 11-07-2002, 09:05 AM
  4. Can't find problem
    By b-ref in forum C Programming
    Replies: 2
    Last Post: 12-06-2001, 05:39 AM
  5. can anyone find the problem in my code
    By ArseMan in forum C++ Programming
    Replies: 2
    Last Post: 09-20-2001, 09:02 PM