#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <conio.h>
int main(void)
{
int **p;
int i, j;
int M, N;
char s = 'n';
while (s != 'Y' && s != 'y')
{
printf("\nEnter the number of rows in the array M = \n");
scanf_s("%d", &M);
printf("\nEnter the number of columns in the array N= \n");
scanf_s("%d", &N);
if ((p = (int**)calloc(N, sizeof(int*))) == 0)
{
printf("Memory allocation failure *p \n");
exit(1);
}
for (j = 0; j < N; j++)
if ((p[j] = (int*)calloc(N, sizeof(int))) == 0)
{
printf("Memory allocation failure *p[] \n");
exit(1);
}
printf(" Array p[i][j]:\n\n");
for (i = 0; i < M; i++)
{
for (j = 0; j < N; j++)
{
p[i][j] = rand() % (M*N); // 36
printf(" %3d ", p[i][j]); // 37
}
printf("\n");
}
printf("\n\n");
int K;
printf("\nEnter a number of column to delete K = \n");
scanf_s("%d", &K);
for (i = 0; i < M; ++i) {
for (j = K - 1; j < N - 1; ++j)
{
p[i][j] = p[i][j + 1];
j == K - 1; // 50
}
}
printf(" Array p[i][j]:\n\n");
for (i = 0; i < M; i++)
{
for (j = 0; j < N - 1; j++)
{
printf(" %5d ", p[i][j]);
}
printf("\n");
}
printf("\n\n");
for (j = 0; j < N; j++)
free(p[j]);
free(p);
printf("Close program \n Y - Yes N - No \n");
s = _getch();
}
return 0;
}
Output:
При
j == K - 1; // 50
Выдаёт
При этом код работает идеально