Thread: calculating elements of arrays

  1. #1
    Registered User
    Join Date
    Nov 2003

    calculating elements of arrays

    Hi, can someone help me with this?

    I am a student and we're working on this assignment. We are to write a program that declares three two-dimensional arrays, named first, second, and third. Initialize the first array when it is declared.

    Calculate each element in the second array by taking 27% of each element in the first array. Use pointer notation in this function. Send the name of the first array and the name of the second array as arguments to the function. This function will not return any value.

    Add the first array to the second array and place the sum in the third array. Use array notation in this function. Send the name of the first array, the name of the second array, and the name of the third array as arguments to the function. This function won't return any value.

    Use the following data to initialize only the first array in main.
    1.0 4.0 7.0 10.0
    2.0 5.0 8.0 11.0
    3.0 6.0 9.0 12.0

    use the #define to set up constants for the number of rows and columns in the array:
    #define r 3
    #define c 4.

    Please help, thanks!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    So can you do any of your homework at all, or are you completely helpless in this task?

    You'll learn more by
    a) trying to do something
    b) any answers we give will be more tuned to your specific problems.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    It looks pretty straightforward:
    /* Process */
    a = someval;
    b = a * .27;
    c = a + b;
    The principle is the same except you're working with arrays:
    /* Process */
    for ( i = 0; i < r; i++ ) {
      for ( j = 0; j < c; j++ ) {
        b[i][j] = a[i][j] * .27;
        c[i][j] = a[i][j] + b[i][j];
    Swap out the array notation for pointer notation and you're all set. Try to remember next time that difficult problems only seem that way. Most of the time if you dig down a little bit you'll find that the solution is really very simple.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 08-04-2008, 08:27 PM
  2. Comparing elements of character pointer arrays
    By axe in forum C Programming
    Replies: 2
    Last Post: 11-14-2007, 12:20 AM
  3. Calculating # of Elements in Array
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 04-15-2002, 12:08 PM
  4. Pointer of arrays - how do I access their elements?
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 10-11-2001, 11:28 PM
  5. elements of arrays; functions
    By sballew in forum C Programming
    Replies: 6
    Last Post: 09-03-2001, 01:48 AM