私のプログラムを理解し、完成させるためにあなたの助けを求めたいです。
これは私がしなければならないことです:
「プログラムを実行する必要があります。最初に、吸収する 2 次元の整数 arr [M] [N]。M - 行数 N - 列数。(行列サイズはユーザーから受け取りました) 2 つ。プログラムは補助関数を使用します。 「シフト」は、図に示すように、行列の値を右に 1 桁移動します (1 の代わりに 2、2 の代わりに 3、3 の代わりに 4、... 19 の代わりに 20、最初の 20 の代わりに入力) ). Shift は関数を作成し、サンプル マトリックス ループで 3 回呼び出す必要があります.."
例の写真:
エラー メッセージ:
私があきらめた問題を解決しようとした後、私のコードのどこが間違っているのかを理解するためにあなたの助けを求めたい. メモリのことですか?これは私のコードです:
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
#include "malloc.h"
void shift (int **arr,int rows,int cols);
void freemalloc ( int **arr,int rows);
void main()
{
int **arr,cols,rows;
int i,j;
printf("please insert rows and columns of the matrix: ");
scanf_s("%d%d",&rows,&cols);
arr=(int **)malloc(rows*sizeof(int *));
for(i=0; i<rows; i++)
arr[i]=(int *)malloc(cols*sizeof(int));
for (i=0; i<rows; i++)
for (j=0; j<cols; j++)
{
printf("rows %d , cols %d :\n", i, j);
scanf_s("%d", &arr[i][j]);
}
shift (arr,rows,cols);
freemalloc (arr,rows);
system("pause");
return ;
}
void shift (int **arr,int rows,int cols)
{
int i,j,temp=0;
for(i=0; i<rows ; i++ )
for( j=0 ; j<cols ; j++);
{
temp=arr[i][j];
arr[i][j]=arr[i][cols-1];
arr[i][cols-1]=temp;
}
for(i=0; i<rows ; i++)
{
for(j=0; j<cols ; j++)
{
printf("%d ",arr[i][j]);
}
printf("\n");
}
}
void freemalloc ( int **arr,int rows)
{
int i;
for (i=0 ; i<rows ; i++)
{
free(arr[i]);
}
free(arr);
}