I have a project in C and I have to scan an array[10][15] diagonally as in the picture below.

I would like to help me to find how to scan the array this way…
Thank you very much.
P.S sorry for my english(I’m Greek)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Notice that along each diagonal, the difference*
i - jis constant. So you have a nested double loop, where the outer one goes over the difference:First round: Difference -14,
arr[0][14]Second round: Difference -13,
arr[0][13],arr[1][14]…
last round: Difference +9,
arr[9][0].In code:
Note the appearance of the numbers
10and15in the code; the picture is readily generalized to arbitrary array bounds.*) Or, as @Alexey points out, the sum
i + jis constant, depending on where the origin is in your picture; in that case, modify the loop as follows: