Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在c语言中,如何选择一行来计算矩阵减法_C - Fatal编程技术网

在c语言中,如何选择一行来计算矩阵减法

在c语言中,如何选择一行来计算矩阵减法,c,C,我有大小为2x3{7,4,4}的矩阵A和大小为2x3{4,4,1}的矩阵B以及一个数组[c]={5 5 2} 我希望用户选择一行进行减法运算,如果行减法运算大于数组,它将要求用户选择另一行 我的问题是,如果我选择行1减法,{7}-{4}={3 3},第三个值大于2,它应该中断并要求用户选择另一行,但我的代码不是这样工作的 while(count!=0){ printf("enter row number"); scanf("%d",&i); if(running[i]){

我有大小为2x3{7,4,4}的矩阵A和大小为2x3{4,4,1}的矩阵B以及一个数组[c]={5 5 2}

我希望用户选择一行进行减法运算,如果行减法运算大于数组,它将要求用户选择另一行

我的问题是,如果我选择行1减法,{7}-{4}={3 3},第三个值大于2,它应该中断并要求用户选择另一行,但我的代码不是这样工作的

while(count!=0){
  printf("enter row number");
  scanf("%d",&i);
  if(running[i]){
    exec=1;
    for(j=0;j<column;j++){
      if(A[i][j]-B[i][j]>array[j]){
        exec=0;
        break;
      }
    }
    if(exec){
      printf("Row %d is executing\n",i+1);
      running[i]=0;
      count--;
      break;
    }
  }      
} 

您好,请使用do while循环查找下面的代码

注意:我正在静态初始化数组,如果需要,可以使用malloc动态分配

#include <stdio.h>

int main()
{
  int rowNum,i,j;
   char execute = 'N' ;   // flag variable used to repeat the loop


   int A[2][3] = {7,7,7,4,4,4};       // Allocate the matrices dynamically if required
   int B[2][3] = {4,4,4,2,2,2} ;

   int c[3] = {5,5,2};

   do {
             execute = 'N';            
             printf("\nEnter row number to perform substraction:");
             scanf("%d",&rowNum);

             if(rowNum <= 2)   // checking whether entered row number is greater than 2

             {  
            for( i = rowNum-1, j =0 ; j <3 ; j++)
             {   
            if((A[i][j] - B[i][j]) > c[j] )
                {
                    execute = 'Y' ;
                    printf("Condition failed,Enter valid row number");
                    break ;
                    }


        }
    }
    else
    printf("Crossed max number of rows\n");
}

while(execute=='Y');


 return 0 ;
 }      

它输出第1行是ExecutionExplain r、running、count。。r应该是列的编号如果我有4行,则第1行和第2行可以进行减法运算。如果row1成功,如何实现它要求用户输入其他行来执行加法和加法,就像else{execute='Y';continue;}在ifA[i][j]-B[i][j]>c[j]块之后的语句一样。