Write fun to implement D=B+B ‘by storing B in D with B transpose. The results are printed in the main function.
For example, enter the following matrix: its transpose matrix is:
Then the program output:
Do not change anything in main or the other functions; just put some statements you wrote in curly braces for fun.
The code is as follows:
#include<conio.h>
#include<stdio.h>
void fun(int b[3] [3].int d[3] [3])
{
int i,j,t[3] [3];
for(i=0; i<=2; i++)for(j=0; j<=2; j++) t[i][j]=b[j][i];for(i=0; i<3; i++)for(j=0; j<3; j++) d[i][j]=b[i][j]+t[i][j]; } main() {int b[3] [3] = {{1.2.3}, {4.5.6}, {7.8.9}},c[3] [3];
int i,j;
FILE*out;
fun(b,c);
out=fopen("outfile.dat"."w");
for(i=0; i<3; i++) {for(j=0; j<3; j++) {printf("%7d",c[i][j]);
fprintf(out,"%7d",c[i][j]);
}
printf("\n");
fprintf(out,"\n");
}
fclose(out);
}
Copy the code
The output running window is as follows:
Other exercises this week
C programming column
C programming > 12 weeks ① Write the function fun, this function is: move the contents of the string, move the first to the NTH character, move the NTH +1 to the last character to the front of the string.
C programming > 12 weeks ② Please write a function fun, its function is: STR in the string in addition to the minor index is odd, ASCII value is odd characters, all the rest of the characters are deleted, the rest of the string formed by a new string in the array of s.
③ The records of known students are composed of student numbers and grades. The data of M students has been stored in the array of a structure. Write fun, which finds the highest student record and returns the main function with parameters.
C programming > 12 weeks ④ Please write a function fun, this function function is: D=B+B ‘, that is, the matrix B plus B transpose, stored in the matrix D. The results are printed in the main function.
⑤ Assume that the input string contains only letters and ‘#’ signs. Write fun to make sure that the end of the string contains no more than m ‘#’ signs. If there are more than m ‘#’ signs, delete the extra ‘#’ signs. If there are fewer than or equal to m, nothing is done, and the ‘#’ in the middle and before the string is not deleted.
Student = student; student = student; student = student; student = student; The number of students with above-average scores is returned by parameter n, and the average score is returned by the function value.
⑦ Assume that the input string contains only letters and “#” signs. Write fun, which removes all “#” signs from the string except the “#” sign at the end. The parameter p already refers to the last letter in the string.
C language programming > 12 weeks was the student’s record is composed of student id and grades, M data has in the main function of student in the structure array STU, please write the function fun, its function is to: the specified data within the scope of the students in q referred to in the array, specify scores within the scope of the number of students value is returned by the function.
The harder you work, the luckier you get! Come on, Aoli!!