Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function to determine the number of T-junction in a city. You will be gi

ID: 3569057 • Letter: W

Question

Write a function to determine the number of T-junction in a city. You will be given a city map as a 100 by 100 integer array. The element in the array will be 1 or 0. An element is a T-junction, if it is 1, and EXACTLY three of its neighbors are also 1. In right graph(4*4 sample array), blue ones are T-junctions. We

Write a function to determine the number of T-junction in a city. You will be given a city map as a 100 by 100 integer array. The element in the array will be 1 or 0. An element is a T-junction, if it is 1, and EXACTLY three of its neighbors are also 1. In right graph(4*4 sample array), blue ones are T-junctions. We???ve given you the code (lab_9_4_sample.c) with I/O already, you can input the filename directly, if code and input file is in the same directory. You SHOULD ONLY modify the T_junction function Input filename: 1. In Number of T-junction is 0 Input filename: 2. In Number of T-junction is 392 Input filename: 3. In Number of T-junction is 1160 Input filename: 4. In Number of T-junction is 0

Explanation / Answer

int T_junction(int a[100][100])
{
   int i,j,k,l,count=0;
   for(j=1;j<99;j++)
   {
       if(a[0][j+1]==1)&&(a[0][j-1]==1)&&a[1][j]==1)&&(a[0][j]==1)
       count++;
       if(a[99][j+1]==1)&&(a[99][j-1]==1)&&a[98][j]==1)&&(a[99][j]==1)
       count++;
       if(a[j+1][0]==1)&&(a[j-1][0]==1)&&a[j][1]==1)&&(a[j][0]==1)
       count++;
       if(a[j+1][99]==1)&&(a[j-1][99]==1)&&a[j][98]==1)&&(a[j][99]==1)
       count++;
   }
   for(i=1;i<99;i++)
   {
       for(j=1;j<99;j++)
       {
           if(a[i][j]==1)
           {
               if(a[i-1][j]==1)&&(a[i+1][j]==1)&&(a[i][j+1]==1)
               count++;
               if(a[i-1][j]==1)&&(a[i+1][j]==1)&&(a[i][j-1]==1)
               count++;
               if(a[i][j-1]==1)&&(a[i][j+1]==1)&&(a[i-1][j]==1)
               count++;
               if(a[i][j-1]==1)&&(a[i][j+1]==1)&&(a[i+1][j]==1)
               count++;
                              
           }
       }
   }
   return count;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote