write the psuedocode for a computer program that computes the sum of the numbers on the diagonal of a 10 x 10 integer array named numbers.
Here is what i got but i'm not sure:

int SIZE = 10;
    int [ ] numbers = new int[SIZE] [SIZE];
     for (int I = 0; I < numbers.length; I++)
         numbers [ I ] = sum [I];
         print sum;

Recommended Answers

All 3 Replies

ok. First there are several thing I would like to point out. When you are summing you set the number at I equal to the sum at I. What you want to do is create another variable outside of the loop, and add the number at the I value to the sum variable. Second you will want to take a look at 2D arrays also to traverse the 2D array you will need a nested for loop (a for loop inside of the for loop) and make sure you don't use the same counter. You will also want to print out the sum after your outer for loop has completed.

I hope this helps

Ok thanks a lot

To sum a diagonal you just need one loop and one counter. You don't want nested loops

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.