Question

In an 2D array I have the following data stored. Now I have to do code...

In an 2D array I have the following data stored. Now I have to do code in C language to do the following:

If distance between 1 &4 and 5&8 in any line is greater than 2 , then delete that row. And then update the 2D array. If there is no pair of 1 &4 or 5&8 in any row skip that row.

Please help to do the code in C.

0 1 2 3 4 9

0 1 2 3 7 8 9

0 1 2 6 7 3 4 9

0 1 2 6 7 8 9

0 5 6 2 3 4 9

0 5 6 2 3 7 8 9

0 5 6 7 3 4 9

0 5 6 7 8 9

Result:

0 1 2 3 4 9

0 1 2 3 7 8 9

0 1 2 6 7 8 9

0 5 6 2 3 4 9

0 5 6 7 3 4 9

0 5 6 7 8 9

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please let me know you need more information:-

========================================

====

#include <stdio.h>

int main()
{
  
int myArray[8][8] = {
{ 0,1,2,3,4,9 },

{ 0,1,2,3,7,8,9 },

{ 0,1,2,6,7,3,4,9 },

{ 0,1,2,6,7,8,9 },

{ 0,5,6,2,3,4,9 },

{ 0,5,6,2,3,7,8,9 },

{ 0,5,6,7,3,4,9 },

{ 0,5,6,7,8,9 }

};
  
for(int i =0 ; i < 8 ;i++){
int print = 1;
for(int j=0;j<8;j++){
  
if(myArray[i][j] == 1){
//printf("%d == > j=%d \n" , myArray[i][j] ,j);
for(int k = j,t=j ; k<8-j;k++,t++){
// printf("%d == > k=%d , x=%d\n" , myArray[i][k] ,k,t);
if(myArray[i][k] == 4 && t>4){
//swap the array Do not print this.
print = 0;
break;
}
}
}
if(myArray[i][j] == 5){
//printf("%d == > j=%d \n" , myArray[i][j] ,j);
for(int k = j,x=1 ; k<8-j ;k++,x++){
//printf("%d == > k=%d , x=%d\n" , myArray[i][k] ,k,x);
if(myArray[i][k] == 8 && x>4){
//swap the array Do not print this.
print = 0;
break;
}
}
}
  
}
if(print != 0){
for(int p=0;p<(sizeof(myArray[0])/sizeof(myArray[0][0]));p++){
printf("%d ",myArray[i][p]);
}
printf("\n");
}

}
  

return 0;
}

==

====

===

OUTPUT:-

==

0 1 2 3 4 9 
0 1 2 3 7 8 9  
0 1 2 6 7 8 9  
0 5 6 2 3 4 9  
0 5 6 7 3 4 9  
0 5 6 7 8 9 

==

Please let me know you need more information:-

==

Thanks

Add a comment
Know the answer?
Add Answer to:
In an 2D array I have the following data stored. Now I have to do code...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The following program simulates shuffling a deck of cards. (The line numbers are not ) part of the code). Without changing its functionality, rewrite the program by replacing the 2D array card [5...

    The following program simulates shuffling a deck of cards. (The line numbers are not ) part of the code). Without changing its functionality, rewrite the program by replacing the 2D array card [52] [2] with a double pointer char **card and replacing the code between line 12 and line 26 with a function. The function prototype could be void shuffleCards (char **, char [, char [) 1 7/Shuffling cards 2 4 using namespace std; 6 main() #include #include <cstdlib> <iostream>...

  • C++ program Write a program which: 1. Enters data into the 2D array of integers which...

    C++ program Write a program which: 1. Enters data into the 2D array of integers which is 5x5 The data should be entered with an assignment statement using nested for loops that is do not scan in the data. The data should be: 1 2 4 8 16 1 3 9 27 81 1 4 16 64 256 1 5 25 125 625 1 6 36 216 1296 2. Print out the following using a nested for loop Row 0:...

  • In assembly language, reverse an array of integers: # The array will be stored in memory...

    In assembly language, reverse an array of integers: # The array will be stored in memory # The location of arr[0] is SP # The location of arr[1] is SP+1 # The location of arr[2] is SP+2 # ... and so on # The size of the array N will be stored in SP-1 # The SP register may be initialized to any value 2: 1024; # Initialize the SP register to 1024 (start of the array) # ALL other...

  • Write a function called ZeroCornersSecondRow that sets the corners of a 2D array to zero and...

    Write a function called ZeroCornersSecondRow that sets the corners of a 2D array to zero and also outputs the second row. The input arguments: • inArray: A double precision 2D array of size nxn, where n is at least 3. The output arguments: outArray: A double precision 2D array of size nxn that is a copy of inArray except with the corners set to zero. • secondRow: A double precision 1D array of size n. This is the second row...

  • The last element in each array in a 2D array is incorrect. It’s your job to...

    The last element in each array in a 2D array is incorrect. It’s your job to fix each array so that the value 0 is changed to include the correct value. In the first array, the final value should be the length of the first array. In the second array, the final value should be the sum of the first value, and the second to last value in the array. In the third array, the final value should be the...

  • 1. What is the output of the following code segment? int array[] = { 8, 6,...

    1. What is the output of the following code segment? int array[] = { 8, 6, 9, 7, 6, 4, 4, 5, 8, 10 }; System.out.println( "Index Value" ); for ( int i = 0; i < array.length; i++ ) System.out.printf( "%d %d\n", i, array[ i ] ); 2. What is the output of the following code segment? char sentence[] = {'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u' }; String output = "The sentence...

  • java Write methods for 2d 1. a method to calculate the sum of a 2d double...

    java Write methods for 2d 1. a method to calculate the sum of a 2d double array 2. a method to calculate the sum of each row of a 2d double array 3. a method to calculate the sum of each column of a 2d double array 4. a method to calculate the average of a 2d double array 5. a method to calculate the average of each row of a 2d double array 6. a method to calculate the...

  • Write a method that takes in a two-dimensional array of integers, do some calculation for each...

    Write a method that takes in a two-dimensional array of integers, do some calculation for each row in the two-dimensional array, and returns a one-dimensional array of sums for each row. Your code must work any array dimensions, including jagged arrays. The calculations are: • Sum of each row • Maximum value of each row • Minimum value of each row • Average of each row Here is an example an array passed and returns an array of sums for...

  • Programming Language: C++ Develop a seat reservation system for your airline. Consider the following airline seating...

    Programming Language: C++ Develop a seat reservation system for your airline. Consider the following airline seating pattern: A         1          2          3          4          5          6          7          8          9          ……    100 B         1          2          3          4          5          6          7          8          9          ……    100 AISLE C         1          2          3          4          5          6          7          8          9          ……    100 D         1          2          3          4          5          6          7          8          9          ……    100 Either use 2D STL array (array that contains array) or 4 single dimensional STL arrays of size 100. Write a program to display a menu to the user with the options to reserve a seat of choice, reserve a window seat, reserve an aile seat, reserve a seat (any available), withdraw reservation, update reservation (change seat) and display...

  • Q21 Read the following code: 8 Points public class Main { public static int[][] doStuff() {...

    Q21 Read the following code: 8 Points public class Main { public static int[][] doStuff() { int[][] array2D = new int[3][2]; for (int i = 0; i < array2D.length; i++) { for (int j = 0; j < array2D[0].length; j++) { array2D[i][j] = (i+j)%2; } } return array2D; فه public static void main(String[] args) { int[][] a = doStuff(); مہ سره Q21.1 What are the contents of array a? 6 Points Write your answer as if printing the elements row-by-row....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT