C Program Shortest Distance in Matrix
#include <stdio.h>
/* 求n的絕對值 */
int abs(int n) {
return n > 0 ? n : -n;
}
int main(int argc, const char * argv[]) {
int N, x, y;
int row, column;
printf("Dimension -> "); scanf("%d", &N);
printf("Point -> "); scanf("%d %d", &x, &y);
x--;
y--;
for (row = 0; row < N; row++) {
for (column = 0; column < N; column++) {
// Shortest distance from (row, column) to (x, y)
printf("%3d ", abs(row - x) + abs(column - y));
}
printf("\n");
}
return 0;
}
Learn More :
Matrix
- C Program To Find Transpose Of A Matrix
- C Program To Multiply Two Matrices
- C Program To Print Tridiagonal Matrix
- C Program To Understand Use Of Pointers In MATRIX
- C Program : 4x4 Matrix Keypad connected to Arduino. This code prints the key pressed on the keypad to the serial port.
- C Code/Program For Swap Matrix
- matrix sort in C Program
- Sequential Matrix Multiplication C Program
- C Program to calculate sum of two m*n matrices & store the result in 3 matrix
- C Program to accept m*n matrix from user and display the elements of given matrix using function
- C Program to calculate the sum of elements of upper triangle of a n*n matrix using DMA
- C program to display the transpose of given 3 X 3 matrix
- Calculate sum of element of upper triangle of m*n matrix by using dynamic memory allocation
- Calculate sum of non-diagonal element in m*n matrix C Program
- Calculate sum of element of lower triangle of m*n matrix by using dynamic memory allocation
- C Program To Read The Adjecancy Matrix of Directed Graph And Convert It Into Adjecancy List
Shortest Distance