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 947359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:04:15+00:00 2026-05-15T23:04:15+00:00

int numbs[4][4] = 1, 2, 3, 4 5, 6, 7, 8 9, 10, 11,

  • 0
int numbs[4][4] = 
     1,  2,  3,  4
     5,  6,  7,  8
     9, 10, 11, 12
    13, 14, 15, 16;

When i print it, it should print like this.

1 2 3 4, 8, 12,16, 15, 14, 13, 9, 5, 6, 7, 11, 10, (ie clockwise direction spiral):

---\ //first right, then down, left, up and repeat
/-\|
|-/|
\--/
  • 1 1 Answer
  • 0 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-15T23:04:16+00:00Added an answer on May 15, 2026 at 11:04 pm

    Here’s my stab at it:

        static void Spiral(int[,] m)
        {
            int n = m.GetUpperBound(0);
            for (int i = 0; i < n / 2; ++i)
            {
                for (int j = i; j <= n - i; ++j)
                    Console.Write(m[i, j] + " ");
                for (int j = i + 1; j <= n - i; ++j)
                    Console.Write(m[j, n - i] + " ");
                for (int j = i + 1; j <= n - i; ++j)
                    Console.Write(m[n - i, n - j] + " ");
                for (int j = i + 1; j < n - i; ++j)
                    Console.Write(m[n - j, i] + " ");
            }
    
            Console.Write(m[n / 2, n / 2]+" ");
            if (n % 2 == 1)
            {
                Console.Write(m[n / 2, n / 2+1] + " ");
                Console.Write(m[n / 2+1, n / 2+1] + " ");
                Console.Write(m[n / 2+1, n / 2] + " ");
            }
        }
    
        static void Main(string[] args)
        {
            int[,] myArray = new int[,]{
                {11, 12, 13, 14, 15},
                {21, 22, 23, 24, 25},
                {31, 32, 33, 34, 35},
                {41, 42, 43, 44, 45},
                {51, 52, 53, 54, 55}
            };
            Spiral(myArray);
        }
    

    The output is:

    11 12 13 14 15 25 35 45 55 54 53 52 51 41 31 21 22 23 24 34 44 43 42 32 33
    

    edit: Works for both even and odd sized square matrices now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

int a[2]; This in memory actually looks like: //Assuming int is 2 bytes add=2000,
So this probably would be easy if done like this public static [] nums(int
To assign specific value to 1D array I'm using LINQ like so: int[] nums
I have a class like this class aClass { public: aClass() : N(5) {}
i have written this python program. whenever i run the script using parameters like
This is a simplified code to explain the problem: int *nums[10]; *nums[0] = 5;
Would int[] nums = { 2, 3, 3, 4, 2, 1, 6, 7, 10
public class Arrys { private int[] nums; //Step 3 public Arrys (int arrySize) {
CODE: #include <stdio.h> main() { int nums[100], i; char answer; int count = 0;
header file: private: vector<int*>* nums; public slots: void buttonClicked(); cpp file: NewWindow(){ int one

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.