473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

square matrix, assigning number to diagonals and top row

2
Im using codeblocks
Lets say primary matrix is:
88888
88888
88888
88888
88888
I need to make it to:
00000
80808
88088
80808
08880

Thank you
Jun 8 '15 #1
3 1366
weaknessforcats
9,208 Expert Mod 8TB
You just did it.

Just put your desired result into code.

Like, array[1][1] = 0; etc...
Jun 8 '15 #2
nazzii
2
Well on this exercise it should be three c code functions that replaces 8 with 0. 1 for main diagonal, other for secondary diagonal and finaly top line functions. And finally a functions that prints everything. At the momentu i have functions that makes matrix, also functions that replaces primary diagonal and prints everything. Secondary diagonal and top line functions are the Ones i can not write properly...
Jun 9 '15 #3
weaknessforcats
9,208 Expert Mod 8TB
Look at your desired output. The forward diagonal starts at the last row of the array in the last position. Your example is a 5 element row so the forward diagonal starts at [0][0]. The next location is the previous row plus one more position since it is a diagonal. That would be [1][1]. Then [2][2], etc.

The reverse diagonal starts at [0][4] then advances to the next row less 1 more byte since the reverse diagonal retreats. That would be [1][3], [2][2], [3][1], and [4][0].

If you look at these indexes you can see a progression where you can use a loop counter to advance the rows plus another counter where you add 1 for the forward diagonal and subtract 1 for the reverse diagonal.

Your functions will need the address of the array, the number of rows and columns and maybe a toggle to tell the function to make the diagonal forwards or reverse. Maybe even another argument for the value to place in the diagonal positions.

The top line is simply places a zero in [0][0],[0][1], until you reach the end of the row.
Jun 9 '15 #4

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

Similar topics

2
by: JustSomeGuy | last post by:
mx = Cols/2; if ((mx * 2) != Cols) // Odd. ++mx; } for (y1=0; y1 < Rows; ++y1) { y2 = Rows-1 - y1; for (x1=0; x1 < mx; ++x1)
0
by: YUSUF ISIAKA | last post by:
Him please help me with the codes for the following questions: 1. Write a program in c/c++ to compute the inverse of a square matrix. 2. Write a program in c/c++ to compute the determinant of a...
2
by: prads | last post by:
Hello, Can anybody tell me how i shud go about to perform the transpose of a nonsquare matrix array. Pls give me an idea so that i can write one based on that and then post queries if errors r...
2
by: whodgson | last post by:
This is a learning problem which is not part of an assignment or homework so there is no urgency. i`ve spent hours writing and ammending this rotate() function to no avail. So now i`ve obtained the...
1
by: sanaanand2008 | last post by:
can u pls help me out write the prgm to check whether the entered matrix is a magic square or not?
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
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...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.