Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 460537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:53:01+00:00 2026-05-12T22:53:01+00:00

I thought this problem had a trivial solution, couple of for loops and some

  • 0

I thought this problem had a trivial solution, couple of for loops and some fancy counters, but apparently it is rather more complicated.

So my question is, how would you write (in C) a function traversal of a square matrix in diagonal strips.

Example:

1  2  3
4  5  6
7  8  9

Would have to be traversed in the following order:

[1],[2,4],[3,5,7],[6,8],[9]

Each strip above is enclosed by square brackets.
One of the requirements is being able to distinguish between strips. Meaning that you know when you’re starting a new strip. This because there is another function that I must call for each item in a strip and then before the beginning of a new strip. Thus a solution without code duplication is ideal.

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T22:53:01+00:00Added an answer on May 12, 2026 at 10:53 pm

    Here’s something you can use. Just replace the printfs with what you actually want to do.

    #include <stdio.h>
    
    int main()
    {
        int x[3][3] = {1, 2, 3,
                       4, 5, 6,
                       7, 8, 9};
        int n = 3;
        for (int slice = 0; slice < 2 * n - 1; ++slice) {
            printf("Slice %d: ", slice);
            int z = (slice < n) ? 0 : slice - n + 1;
            for (int j = z; j <= slice - z; ++j) {
                printf("%d ", x[j][slice - j]);
            }
            printf("\n");
        }
        return 0;
    }
    

    Output:

    Slice 0: 1
    Slice 1: 2 4
    Slice 2: 3 5 7
    Slice 3: 6 8
    Slice 4: 9
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright. I thought this problem had something to do with my rails app, but
This is a thought exercise, not a particular problem, but I'd like to hear
Okay, so this is not the first time I've had this problem, but it
At first I thought this was a problem with my app, but it seems
since I'm trying to solve this problem for some days, I thought about giving
Just wondering if you had any thoughts on this problem. I want to make
Never thought I'd have this problem :) The following snippet of code works in
I thought I'd throw out this problem to see what elegant solutions folk could
I thought to share this relatively smart problem with everyone here. I am trying
This is a thought problem, and one I have been wrestling with for about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.