Multiplying a small matrix inside a bigger matrix in C

I have a 4*4 matrix and I want to divide it into 4 blocks of 2*2 matrices so that I can multiply them by a different 2*2 matrix. How do I do that in C? A = [1 2 3 4; 2 3 4 5; 3 4 5 6; 4 5 6 7] B = [2 3; 4 5] I know the matrix form is from MATLAB but it's just easier to write it that way here. Just in case you weren't clear, I wanted to multiply B, into the 4 different blocks

在C中将较大的矩阵乘以一个小矩阵

我有一个4 * 4的矩阵,我想把它分成4 * 2 * 2矩阵块,以便我可以乘以不同的2 * 2矩阵。 我如何在C中做到这一点? A = [1 2 3 4; 2 3 4 5; 3 4 5 6; 4 5 6 7] B = [2 3; 4 5] 我知道矩阵形式来自MATLAB,但在这里编写它就更容易。 如果你不清楚,我想把B乘以A的4个不同的块,即[1 2; 2 3],[3 4; 4 5],[3 4; 4 5]和[5 6; 6 7] ... 以下是我迄今为止所做的结果导致了糟糕的答案: for (i = 1; i<= 4; i++) {

Multiplying matrix columns

I have a matrix with n rows and 3 columns, and I should multiply row n column 2 with row n column 3. So if I have a matrix that looks like this: 1 2 3 4 5 6 7 8 9 Then I should multiply 2 with 3, 5 with 6 and 8 with 9, and create a matrix or an array that holds results: 6 30 72 How can I do that in C? Since you are interested in learning C, an outline should do :-) The output is going t

乘以矩阵列

我有一个有n行和3列的矩阵,我应该将第n行第2列与第n行第3列相乘。所以,如果我有一个看起来像这样的矩阵: 1 2 3 4 5 6 7 8 9 然后,我应该用3乘以2,用6乘以8,用9乘以8,并创建一个矩阵或一个包含结果的数组: 6 30 72 我如何在C中做到这一点? 既然你对学习C感兴趣,大纲应该这样做:-)输出将是一个单独的列向量。 输入到你的函数是一个矩阵,有一个维度pxq,和两个列号c1和c2。 至少有两种方法不能剥皮。 一个

what's wrong with my stat() function in C in linux

I'm trying to list file infos(including directories etc) using stat() It works fine when I give "."(current directory) as argv[1] (ex. $./a.out .) but has an error when I give other directory such as "..", "/" etc. stat function returns -1(fail) when after direntp points ".."(parent directory). here's an example. $ ls -a .. . .. sample temp

我的linux中的stat()函数有什么问题

我试图用stat()列出文件信息(包括目录等) 当我将“。”(当前目录)作为argv [1](例如$。/ a.out。)时,它工作正常。 但是当我给其他目录如“..”,“/”等时有错误 当direntp指向“..”(父目录)后,stat函数返回-1(失败)。 这里是一个例子。 $ ls -a .. . .. sample temple $ ./a.out .. Success: . Success: .. Fail: sample Stat Call Error. Terminate. $ 那么为什么当我给stat()的参数的其他路径时它失败?

Unsual Result when passing pointer as argument

I have implemented a hashmap. struct hashmap_elmnts { char *key; int in_use; void *data; //contains the address of the malloc of struct ussd defined below }; struct hashmap_map { int table_sizel; int size; struct hashmap_elmnts *element ; }; Now, I have another structure USSD typedef struct ussd { cha

将指针作为参数传递时的不确定结果

我已经实现了一个hashmap。 struct hashmap_elmnts {char * key; int in_use; void * data; //包含下面定义的struct ussd的malloc的地址}; struct hashmap_map { int table_sizel; int size; struct hashmap_elmnts *element ; }; 现在,我有另一个结构USSD typedef struct ussd { char menu; int8_

Undefined struct timeval declaration in C

I have a code below #include <stdio.h> #include "mpi.h" #define NRA 512 /* number of rows in matrix A */ #define NCA 512 /* number of columns in matrix A */ #define NCB 512 /* number of columns in matrix B */ #define MASTER 0 /* taskid of first task */ #define FROM_MASTER 1 /* setting a message type */ #define FROM_WORKER 2 /* setting a message type */ MPI_Status statu

C中未定义的struct timeval声明

我有一个代码如下 #include <stdio.h> #include "mpi.h" #define NRA 512 /* number of rows in matrix A */ #define NCA 512 /* number of columns in matrix A */ #define NCB 512 /* number of columns in matrix B */ #define MASTER 0 /* taskid of first task */ #define FROM_MASTER 1 /* setting a message type */ #define FROM_WORKER 2 /* setting a message type */ MPI_Status status;

Realloc is not resizing array of pointers

I keep passing in and returning the dirs_later_array. When I get to "new_size=..." in the else block, I end up with new_size of 2 the second time around. So far so good. But when I do a realloc dirs_later_array = realloc(dirs_later_array, new_size * sizeof(struct dirs_later*)); the sizeof remains at 4, the size of the pointer, for dirs_later_array. I'm able to succesfully stor

Realloc不调整指针数组的大小

我不断传球并返回dirs_later_array。 当我在else块中得到“new_size = ...”时,我第二次得到2的new_size。 到现在为止还挺好。 但是当我做一个realloc dirs_later_array = realloc(dirs_later_array, new_size * sizeof(struct dirs_later*)); 对于dirs_later_array,sizeof保持在4,指针的大小。 我可以成功存储在dirs_later_array [1]中,但是在下一次进入函数时该值会被覆盖。 struct dirs_later** add_struct(const ch

type checking across source files

I spent many hours debugging a problem that turned out to be caused by two source files including two header files in a different order. One of those headers defined _FILE_OFFSET_BITS to 64, and the other header file included <sys/types.h>, which defined off_t to be either 32 or 64 bits long, depending on the setting of _FILE_OFFSET_BITS. I've included below a short example of this si

跨源文件进行类型检查

我花了很多时间调试了一个问题,这个问题原来是由两个源文件引起的,包括两个不同顺序的头文件。 其中一个头文件将_FILE_OFFSET_BITS定义为64,另一个头文件包含<sys / types.h>,它定义了off_t为32位或64位长,具体取决于_FILE_OFFSET_BITS的设置。 我在下面列举了这种情况的一个简短例子。 这是在x86_32 Linux上(包括Debian unstable和CentOS 4.8)。 gcc -Wall main.c other.c,Solaris 9 lint和splint都不能检测

how to find cell index no. in 2

in C programming if an 2-D array is given like ( int a[5][3]) and base address and address of particular element (cell ) is also given and have to find index no. of that element(cell) (row and col no.) can we find that? if yes how? i know the formula of finding address is like this int a[R][C]; address(a[i][j])=ba+size(C*i+ j); if ba, R,C,Size and address(a[i][j]) is given... how to fin

如何找到细胞索引号。 在2

在C编程中,如果给出一个二维数组(例如(int a [5] [3])并且给定了特定元素(单元)的基地址和地址,并且必须找到索引号。 我们可以找到那个元素(单元格)(行和列号)吗? 如果是的话如何? 我知道寻找地址的公式就是这样 int a [R] [C]; address(a [i] [j])= ba + size(C * i + j); 如果给出了ba,R,C,Size和address(a [i] [j])......如何找到i和j的值? 为了找到2变量的值,我们需要2个方程..但我不能

Converting 2d array C code to malloc

I made a program that adds two matrices and displays their sum with a max dimension of 100. /* This program asks the user for 2 matrices called A and B, as integers, and displays their sum, C. The max dimension of each matrix is 100. */ #include <stdio.h> // Construct function void construct() { int m, n, i, j; // Variables int first[100][100], second[100][100], sum[100][10

将2d数组C代码转换为malloc

我做了一个程序,增加了两个矩阵,并显示它们的总和,最大维数为100。 /* This program asks the user for 2 matrices called A and B, as integers, and displays their sum, C. The max dimension of each matrix is 100. */ #include <stdio.h> // Construct function void construct() { int m, n, i, j; // Variables int first[100][100], second[100][100], sum[100][100]; // Matrices variables

Finding the sum of elements of the largest sub array of increasing order in C?

I have a file named sample.txt which contains 1000 integers(both positive and negative numbers). First I copied the file into an array of size 1000 (say a ). My aim is to locate the largest sub array in a and find the sum of elements in it. An array is a sub array if it's consecutive elements are in increasing order. For example in the array {12,23,3,1,-56,2,4,6,45,49,1,2,-10} the sub arr

在C中查找递增顺序的最大子数组元素的总和?

我有一个名为sample.txt的文件,其中包含1000个整数(正数和负数)。 首先,我将文件复制到一个大小为1000的数组(例如a )。 我的目标是找到a中最大的子数组,并在其中找到元素的总和。 如果连续元素按升序排列,则数组是一个子数组。 例如在数组{12,23,3,1,-56,2,4,6,45,49,1,2,-10}中,子数组是{-56,2,4,6,45, 49}。 然后我需要计算这个子数组的元素总和。 下面给出的是我尝试使用C程序来解决问题。 本学期我是一