-
#include
int main()
int x,y,i,j;
printf("Please enter the rows and columns of the sparse matrix");
scanf("%d %d",&x,&y);
int arr[x][y];
printf("Please enter a sparse matrix");
for(i=0;ifor(j=0;jscanf("%d",arr[i][j]);
for(i=0;ifor(j=0;jif(arr[i][j])
printf("%d %d %d",i,j,a[i][j]);
Note: This program uses variable length arrays, which are not suitable for all compilers, so run the modified program to check whether your compiler supports variable arrays.
-
I wanted to do it, but the 4th floor is perfect, and you should give it to him.
If you think what I'm saying is right,。。 Well... You can give me extra points... Well...
-
50 points....For such a simple question, you would use fifty points....
Okay....P.S. I remember that I said this question a few days after I first learned pascal....It's nothing more than scanning, recording...
-
Can you write it clearly?
-
If the array is a square, it can look like this:
for(int i=0;i
If it's an m*n matrix, you'll need to reorganize the array, but the principle is pretty much the same.
-
The first step, double circulation: adjacency matrix + identity matrix.
for i=0 to shangxian (i++)for j=0 to shangxian (j++)if i=j then a[i,j]=a[i,j]+1 (the value on the diagonal of the identity matrix is 1).
nextj,i
In the second step, the resulting matrix is multiplied by itself (double cycle). Matrix multiplication requires a lot of words, so I won't write about it, but I believe you know, at least you should be able to look it up.
In the third step, the matrix obtained after multiplication is compared with the matrix before multiplication, (which is also a double cycle). If it is equal, it will be done, otherwise it will be repeated.
Step 2 and 3. If automated.
The multiplication and comparison process of two and three requires a layer of conditional looping on the outside.
-
Write a general one for you.
If you want other matrices multiplied by a few times, you can modify the values of n and m to include
#define n 3
#define m 4
int array[n][m];
int turn[m][n];
void main()
printf("");
printf("The matrix before transpose is:");
for(i=0;i calls the matrix transpose function.
convert(array,turn);
printf("");
printf("The transposed matrix is:");
for(i=0;ivoid convert(int array[n][m],int turn[m][n])
-
The above one is well written, don't do it.
-
#include
#include
int main()
for(i=0;i<=3;i++) output your input matrix;
printf("");}
printf("");
for(i=0;i<=3;i++) conversion matrix;
printf("");
system("pause");}
-
#include
#define n 1024
void main()
int i, j,k,n,m,a[n][n];
printf(("Please enter m:"
scanf("%d",&m);
printf(("Please enter n:"
scanf("%d",&n);
printf("Please enter %d*%d element:"m,n);
for(j=0;jfor(k=0;kscanf("%d",&a[j][k]);
for(i=0;ifor(j=0;jprintf("%d",a[i][j]);
printf("");
-
Here is an analysis for you... Why has the front been changed, but the back output has not been changed? The reason is simple. You have made two exchanges ...
For example, when i=1 and j=3, you swap t[1][3] and t[3][1], and when the program runs to i=3 and j=1, do you swap t[3][1] and t[1][3] again?
Think about it ... Hehe... Two exchanges were made and all the work was done in vain...
The solution is to define a two-dimensional array to store the swapped values...
#include
using namespace std;
main(),i,j;
int str[3][3];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
for(i=0;i<3;i++)
cout<}return 0;}
-
It's simple, for(i=0; i<3;i++)
for(j=0;j<3;j++) Change j=0 to j=i+1.
-
You changed it 2 times, and of course you changed it back again, hehe
The for loop, which should be terminated when it is executed to t[1][1], is correct.
-
It's to write a decimal to binary conversion.,Original format output.。
It is implemented with heap, and the left sub-node of each node is 2*n, and the right sub-node is 2*n+1
2. 1, True 2, False (there is only one program) 3, False (not necessarily) 4, True. >>>More
Definition of a for loop.
for(the initial value of the variable; termination of operating conditions; The initial value of the first cycle i is 0, and it runs until i=3 stops i=2, and the condition is still satisfied, and the loop body is still executed, and the step size is 1+1 each time >>>More
Hey! This is a very simple function to write, Your Excellency is estimated to have just learned data structures, now learn sorting, lookup, it's easy to give me a reward of two hundred points, I'll help you write it right away. >>>More
I thought about it for a long time and didn't come up with it. >>>More