Now I need help adding arrays

This is a discussion on Now I need help adding arrays within the C Programming forums, part of the General Programming Boards category; So lets say that I want to add arrays, How would I go about doing this. So the array would ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    18

    Now I need help adding arrays

    So lets say that I want to add arrays, How would I go about doing this. So the array would have a size limit of 7 so it would be something like.. int array[7] or would be it size = 7; array[size]? Then how would I go about adding these integers? Would I store another variable in the array's? Like so if I wanted a total of seven array sizes, like array[1][2][3][4][5][6][7]; would i have like 7 different variables , like a,b,c,d,e,f,g,h? or something like that and assign each variable to the array? I'm just very confused.... need help, lots of help. Need the C programming pro's to help me. I feel so lost... so lonely..

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    First you have to figure out what you mean when you say "adding arrays". Do you mean you have two arrays and you want to add them, piece-by-piece? Do you have one array and you want to add all the elements? Do you have two arrays, and you want to glue them together into one big array? Or none of the above?

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    So you want to sum up an entire array?

    Code:
    int sum, i;
    
    for(i = 0, sum = 0; i < size; i++)
      sum += array[i];
    Or am I misunderstanding?

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    18
    Well here is the example that I got from my friend... he made a bet with me that I wouldn't understand array (which I don't) before he comes back on wednesday. So I need to finish this stupid program that he made so I don't lose the bet, very stupid bet, but its just something for us to pass time with.... (sorry i'm a very big newb).

    Code:
    
    #include <stdio.h>
    #include <stdlib.h>
    
    
    // function declarations
    int rawr1(int s, int arr[]);
    int rawr2(int s, int arr[]);
    int rawr3(int s, int arr[]);
    
    int main(void) {
        int x;
        int size = 7;
        int ar[] =  { 2, -5, 13, 6, 4, 2, 2 };
        int ar2[] = { 2, -5, 6, 13, 4, 2, 4 };
        int ar3[] = { 2, 3, -5, 6, 4, 4, 13 };
        int ar4[] = { 2, 2, 4, 4, 2, 13, 7 };
        // Call a function at the end of this function.
        x = rawr1(size, ar);
        printf("rawr1 returned %d\n", x);
    
        // Call functions in a different file.
        x = rawr2(size, ar);
        printf("rawr2 returned %d\n", x);
    
        x = rawr3(size, ar);
        printf("rawr3 returned %d\n", x);
    
        x = rawr3(size, ar2);
        printf("rawr3 returned %d\n", x);
    
        x = rawr3(size, ar3);
        printf("rawr3 returned %d\n", x);
    
        x = rawr3(size, ar4);
        printf("rawr3 returned %d\n", x);
    
        exit (EXIT_SUCCESS);
    }
    
    int rawr1(int s, int arr[]) {
        // and I have no idea what to do here... so.... please help, please have compassion for the weak newb here.
    	}
    
    int rawr2(int size, arr[]){
       // and I have no idea what to do here as well
        }
    
    int rawr3(int size, arr[]){
       // and finally no freakin idea what to do here...
       }

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Feel free to also check out google.

  7. #7
    Registered User
    Join Date
    Oct 2008
    Posts
    18
    I read the lesson, but i barely helps me.. I'm literally a blind newb that has no programming experience except for like 2 VERY VERY VERY VERY BASIC programs... like adding 2 numbers.

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    Then why did you accept the bet, if you cannot program?
    I hate to bring this up, but us writing the program for you would be "cheating."
    I am still assuming you were to sum up every number in that array.
    So, what parts of the lesson did you not understand?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Oct 2008
    Posts
    18
    Well, its not cheating. i'm just asking for help and to understand more about arrays... I understand the

    for loop and how your storing the x and y into the two dimension and then you set that array to x * y. I understand that as well. But what is cout? that place I get lost.

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    This is actually C++, but cout prints stuff to the screen. Basically.
    You do not need to really worry about that, but more about getting the understand of how arrays work and behave.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Oct 2008
    Posts
    18
    Thats what I'm trying to understand.

  12. #12
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    Indeed you are and the tutorial explains it very well how arrays work.
    You have the array, and you have the size of the array.
    If you were given a bunt of papers in real life, and the number of papers, and on each of those papers is a number. Take those numbers and add them up. How would you do that in real world?
    Type it in pseudo code first.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Registered User
    Join Date
    Oct 2008
    Posts
    18
    Ahhh, thank you very much! YOU TRULY ARE THE PROGRAMMING GODDESS!

  14. #14
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Why not wait until you are comprehending what an array is before starting a new thread asking how to perform select task on an array. In my professional opinion, even if you got your code to work it does not demonstrate an understanding of what an array is or does.

  15. #15
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by nifear4 View Post
    Ahhh, thank you very much! YOU TRULY ARE THE PROGRAMMING GODDESS!
    *sigh* that one will probably make the sig. Yet mine never do... though I suppose mine tend to sound a little sarcast or underwhelming.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adding numbers with arrays
    By Oliveira in forum C Programming
    Replies: 4
    Last Post: 04-16-2009, 10:25 PM
  2. Adding arrays with pointers - help
    By chip.litch in forum C Programming
    Replies: 2
    Last Post: 10-02-2008, 11:07 PM
  3. SVN Import Causes Crash
    By Tonto in forum Tech Board
    Replies: 6
    Last Post: 11-01-2006, 02:44 PM
  4. Adding character arrays to strings.
    By w00tw00tkab00t in forum C++ Programming
    Replies: 28
    Last Post: 02-06-2006, 06:03 PM
  5. Adding multidimensional arrays
    By newbie2C++ in forum C++ Programming
    Replies: 3
    Last Post: 11-13-2001, 03:05 PM

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