Thread: multi array references

  1. #1
    Registered User
    Join Date
    Mar 2008
    Location
    brooklyn ny
    Posts
    2

    Smile multi array references

    thanks for comment, the hw question is extremly vague and the entire program only has to do is reference the numbers, all of the numbers and the stlye of the program i chose
    Code:
    #include <cstdlib>
    #include <iostream>
    #include<time.h>
     
    using namespace std;
     
    int main()
     
    {  clock_t start, end;
    double runTime;
    start=clock();
     
        int A[100][100]; //100 not 200
        int j,k;
        A[j][k]=0;//i set all the values of the array to zero 
        for ( j=0;j<100; j++)
        for ( k=0;k<100; k++)
        cout<<A[j][k]; //this was to see if the array got larger correctly
        end=clock();
        runTime=((end-start)/(double)  CLOCKS_PER_SEC);
        printf("Run time is &#37;g seconds", runTime);
        int getch();//this actually has no purpose, i forgot to remove it
        system("PAUSE");
        return 0;
    }
    Last edited by c++ is funky; 03-27-2008 at 08:47 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by c++ is funky View Post
    any ideas would be good
    I agree. Any ideas as to what this program is supposed to do would be handy.

    Anyway:
    Quote Originally Posted by c++ is funky View Post
    Code:
    #include <cstdlib>
    #include <iostream>
    #include<time.h> //I thought it was ctime, but I didn't check.
     
    using namespace std;
     
    int main()
     
    {  clock_t start, end;
    double runTime;
    start=clock();
     
        int A[100][200];
        int j,k;
        A[j][k]=0; //and j and k are ... what, exactly?
        for ( j=0;j<100; j++)
        for ( k=0;k<100; k++) //what happened to 200?
        cout<<A[j][k]; //and A[j][k] is ... what, exactly?
        end=clock();
        runTime=((end-start)/(double)  CLOCKS_PER_SEC);
        printf("Run time is %g seconds", runTime);
        int getch(); //why do you even think this makes sense?
        system("PAUSE");
        return 0;
    }

  3. #3
    Registered User
    Join Date
    Mar 2008
    Location
    brooklyn ny
    Posts
    2
    thanks for comment, the hw question is extremly vague and the entire program only has to do is reference the numbers, all of the numbers and the stlye of the program i chose

    Code:
    #include <cstdlib>
    #include <iostream>
    #include<time.h>
     
    using namespace std;
     
    int main()
     
    {  clock_t start, end;
    double runTime;
    start=clock();
     
        int A[100][100]; //100 not 200
        int j,k;
        A[j][k]=0;//i set all the values of the array to zero 
        for ( j=0;j<100; j++)
        for ( k=0;k<100; k++)
        cout<<A[j][k]; //this was to see if the array got larger correctly
        end=clock();
        runTime=((end-start)/(double)  CLOCKS_PER_SEC);
        printf("Run time is &#37;g seconds", runTime);
        int getch();//this actually has no purpose, i forgot to remove it
        system("PAUSE");
        return 0;
    }

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by c++ is funky View Post
    A[j][k]=0;//i set all the values of the array to zero
    I recognize that that's what you want to do, but what this line actually does is something quite different.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Proper indentation is:
    Code:
    int main()
    {  
        clock_t start, end;
        double runTime;
        start=clock();
     
        int A[100][100]; //100 not 200
        int j,k;
        A[j][k]=0;//i set all the values of the array to zero 
        for ( j=0;j<100; j++)
            for ( k=0;k<100; k++)
                cout<<A[j][k]; //this was to see if the array got larger correctly
        end=clock();
        runTime=((end-start)/(double)  CLOCKS_PER_SEC);
        printf("Run time is %g seconds", runTime);
        int getch();//this actually has no purpose, i forgot to remove it
        system("PAUSE");
        return 0;
    }
    Now people won't be confused or miss something in the code.
    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
    The larch
    Join Date
    May 2006
    Posts
    3,573
    If you want to initialize the array with all values set to 0, you can use:
    Code:
    int A[100][100] = {0};
    What your attempt with j and k does, is assign 0 to a single item in the array (at index j, k - which is particularly bad because j and k are uninitialized and contain garbage).
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 18
    Last Post: 07-25-2007, 07:55 AM
  2. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  3. Template Array Class
    By hpy_gilmore8 in forum C++ Programming
    Replies: 15
    Last Post: 04-11-2004, 11:15 PM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  5. ? passing multi dimensional array to function
    By rc7j in forum C++ Programming
    Replies: 1
    Last Post: 02-10-2002, 02:19 AM