Traverse matrix in clock-wise manner | Bytes (2024)

nivedita prasad

Traverse matrix in clock-wise manner | Bytes (1) 7 New Member

hi
i want a program for
Inward-spiral order matrix.
i.e you have to traverse the matrix in clockwise manner and display the elements,
for eg.

1 2 5 4
8 9 7 1
9 7 6 3
2 3 5 8

output should be 1, 2, 5, 4, 1, 3, 8, 5, 3, 2, 9, 8, 9, 7, 6,7

Regards
Nivedita Prasad

Dec 29 '09 #1

3 Traverse matrix in clock-wise manner | Bytes (2) 5525 Traverse matrix in clock-wise manner | Bytes (3)

newb16

687 Traverse matrix in clock-wise manner | Bytes (4) Contributor

#include <stdio.h>
struct Q{int S,i,j,*A;Q(int o,int*a):S(o),i (0),j(0),A(a){} ;
Q&operator++(){ printf("%d, ",A[i*S+j]);int r(i),p(j);
j>=i-1&&j<S-1-i&&++p;j>=S-i&&j<=i&&--p;j>=S-1-i&&i<j&&++r;j <S-i&&j<i-1&&--r;i=r;j=p;retur n *this;}
};
int main(){
#define size 4
int stuff[size*size]=
{1, 2, 5, 4,
8, 9, 7, 1,
9, 7, 6, 3,
2, 3, 5, 8};
Q q(size,stuff);
for(int i=0;i<size*size ;i++)++q;
}

Dec 29 '09 #2

reply

weaknessforcats

9,208 Traverse matrix in clock-wise manner | Bytes (6) Recognized Expert Moderator Expert

This solution a) should not have been provided as complete code solutions are not to be provided and b) the results of this one is indeterminate due to variables being modified more than once within the same sequence point.

Dec 29 '09 #3

reply

newb16

687 Traverse matrix in clock-wise manner | Bytes (7) Contributor

&& is the sequence point itself. And there is only one '--' or '++' between semicolons.

Dec 29 '09 #4

reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 6698

System Clock

by: James Harriman |last post by:

Hi, I need to be able to measure a time interval in milliseconds on a windows machine. I have tried using time.clock() but it appears to measure time in seconds...Is there a way to measure time more precisely? Regards, James Harriman v38zy@unb.ca

Python

6 3331

Compile-time matrix dimension checking and template friend question

by: Ben Ingram |last post by:

Hi all, I am writing a template matrix class in which the template parameters are the number of rows and number of columns. There are a number of reasons why this is an appropriate tradeoff for my particular application. One of the advantages is that the _compiler_ can force inner matrix dimensions used in multiplication to agree. A _complie-time_ error will be triggered if you write A * B and the number of coluns in A does not equal the...

C / C++

33 47624

clock() function

by: Pushkar Pradhan |last post by:

I'm using clock() to time parts of my code e.g. clk1 = clock(); /* code */ clk2 = clock(); /* calculate time in secs */ ...... clk1 = clock(); /* code */ clk2 = clock();

C / C++

16 4693

speed of int vs bool for large matrix

by: raj |last post by:

Hi, I saw it mentioned that "int" is the fastest data-type for use in C ,that is data storage/retrieval would be the fastest if I use int among the following 4 situations in a 32 bit machine with 4-byte ints: int m; bool m; // assuming I use C++ char m; unsigned char m;

C / C++

14 4973

Segmentation fault in Matrix Multiplication

by: amitnanda |last post by:

Hi Guys, I have a matrix multiplication program in C that multiplies two matrices. When their size is 3*3 or 800*800, the program runs fine. But above that size, I get a "segmentation fault". I need this huge size as part of my assignment.

C / C++

54 4010

Double Clock Experiment

by: CoreyWhite |last post by:

The following experiment is a demonstration of TIME TRAVEL. When writing this program, and testing it out I found that sometimes the program would engage itself in time travel but other times it would not. After careful testing and reprogramming I have optimized the code so it should work every time, however I recommend that you leave the room while it is running and think of something else. It takes about 5 minuets to run so it is...

C / C++

20 5242

Matrix library where's the speed ?

by: Frank-O |last post by:

Hi , Recently I have been commited to the task of "translating" some complex statistical algorithms from Matlab to C++. The goal is to be three times as fast as matlab ( the latest) . I've used various techniques ( loop unrolling, loop jamming...) and tried some matrix libraries : newmat (slow for large matrix) , STL (fast but ..not usefull) , hand coding (brain consuming...), and recently Meschach...

C / C++

12 4099

clock in javascript

by: cenktarhancenk |last post by:

is there a way to display a ticking clock in a web page using javascript? but not in a textbox, rather as text that i can change the style, font etc. cenk tarhan

Javascript

2 8565

matrix class

by: DarrenWeber |last post by:

Below is a module (matrix.py) with a class to implement some basic matrix operations on a 2D list. Some things puzzle me about the best way to do this (please don't refer to scipy, numpy and numeric because this is a personal programming exercise for me in creating an operational class in pure python for some *basic* matrix operations). 1. Please take a look at the __init__ function and comment on the initialization of the list data...

Python

1 9163

Recursive Matrix Multiplication

by: Sozos |last post by:

Hi guys. I have a problem with writing the base case for the following matrix multiplication function I have implemented. Please help. #define index(i,j,power) (((i)<<(power))+(j)) void recMultiply(int i, int j, float a, int k, int l, float b, int x, int y, float c, int s); int i, j, k, s, matrixsize, blocksize, jj, kk, power, bsize; float sum, maxr, total=0.0, startmult, finishmult, multtime; float* A = NULL; float* B = NULL;

C / C++

9456

What is ONU?

by: marktang |last post by:

ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...

General

9272

Changing the language in Windows 10

by: Hystou |last post by:

Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...

Windows Server

10032

Problem With Comparison Operator <=> in G++

by: Oralloy |last post by:

Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...

C / C++

9872

Maximizing Business Potential: The Nexus of Website Design and Digital Marketing

by: jinu1996 |last post by:

In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...

Online Marketing

8711

AI Job Threat for Devs

by: agi2029 |last post by:

Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...

Career Advice

6534

Couldn’t get equations in html when convert word .docx file to html file in C#.

by: conductexam |last post by:

I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...

C# / C Sharp

5141

Trying to create a lan-to-lan vpn between two differents networks

by: TSSRALBI |last post by:

Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

Networking - Hardware / Configuration

1 3805

transfer the data from one system to another through ip address

by: 6302768590 |last post by:

Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

C# / C Sharp

3 2666

Comprehensive Guide to Website Development in Toronto: Expert Insights from BSMN Consultancy

by: bsmnconsultancy |last post by:

In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

General

Traverse  matrix in clock-wise manner | Bytes (2024)

References

Top Articles
Latest Posts
Article information

Author: Dong Thiel

Last Updated:

Views: 6022

Rating: 4.9 / 5 (79 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Dong Thiel

Birthday: 2001-07-14

Address: 2865 Kasha Unions, West Corrinne, AK 05708-1071

Phone: +3512198379449

Job: Design Planner

Hobby: Graffiti, Foreign language learning, Gambling, Metalworking, Rowing, Sculling, Sewing

Introduction: My name is Dong Thiel, I am a brainy, happy, tasty, lively, splendid, talented, cooperative person who loves writing and wants to share my knowledge and understanding with you.