HELP ME TO MAKE PSEUDOCODE OF THIS CODE (C) #include int ec_dist_sq(int x1,int y1,int x2,int y2) { return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2); } int min(int x,int y) { return x>y? y:x; } int main() { int n, i, j; scanf("%d",&n); int mat[n][n]; for(i=0;i
HELP ME TO MAKE PSEUDOCODE OF THIS CODE (C)
#include<stdio.h>
int ec_dist_sq(int x1,int y1,int x2,int y2)
{
return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
int min(int x,int y)
{
return x>y? y:x;
}
int main()
{
int n, i, j;
scanf("%d",&n);
int mat[n][n];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&mat[i][j]);
}
}
int centroid_x = n/2;
int centroid_y = n/2;
int centroid_value=mat[centroid_x][centroid_y];
int min_distance = 9999;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if((i!=centroid_x || j!=centroid_y) && centroid_value==mat[i][j])
{
min_distance = min(min_distance,ec_dist_sq(i,j,centroid_x,centroid_y));
printf("%d %d %d\n",i,j,ec_dist_sq(i,j,centroid_x,centroid_y));
}
}
}
int found = 0;
printf("Nearest elements is at:");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(centroid_value==mat[i][j] && ec_dist_sq(i,j,centroid_x,centroid_y)==min_distance)
{
printf("%d,%d\n",i,j);
found = 1;
}
}
}
if(!found)
printf("no nearest element");
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps