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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Problems on Dynamic Programming
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education