Question
C programming
Write a function that gets a 2-d array of given dimensions of ints. It returns true if the array contains two rows with exact
Examples: On input {{1,2,3,4}, {2,3,4,1}, {1,2,3,4}} it returns true. On input {{1,2,3,4}, {2,3,4,5}, {3,4,5,6}} it returns f
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________


// Function Implementation which checks the equality of two rows

bool contains_equal_rows(int height,int width,const int arr[height][width])
{
   int cnt=0,i,j;
   for(i=0;i<height;i++)
   {
       cnt=0;
       for(j=0;j<width;j++)
       {
           if(arr[0][j]==arr[i+1][j])
           {
               cnt++;
           }
       }
       if(cnt==width)
       return true;
   }
   return false;
}

______________________

//Demo Program

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

// Function Declaration
bool contains_equal_rows(int height,int width,const int arr[height][width]);
int main()
{
const int height=4,width=4;
const int arr[4][4]={{1,2,3,4},
   {2,3,4,5},
                   {3,4,5,6}
                   };
                  
   bool b=contains_equal_rows(height,width,arr);
if(b)
{
    printf("true");
   }
   else
   {
      printf("false");
   }

return 0;
}
bool contains_equal_rows(int height,int width,const int arr[height][width])
{
   int cnt=0,i,j;
   for(i=0;i<height;i++)
   {
       cnt=0;
       for(j=0;j<width;j++)
       {
           if(arr[0][j]==arr[i+1][j])
           {
               cnt++;
           }
       }
       if(cnt==width)
       return true;
   }
   return false;
}

________________________

Output:

C:\Program Files (x86)\Dev-Cpp\MinGW64\bin\CheckEqualityOfTwoRows.exe false -------- Process exited after 0.01899 seconds wit

_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
C programming Write a function that gets a 2-d array of given dimensions of ints. It...
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 aim of this exercise is to check the presence of a number in an array....

    The aim of this exercise is to check the presence of a number in an array. Specifications: • The items are integers arranged in ascending order. • The array can contain up to 1 million items. • The array is never NULL. Implement the method bool Answer::exists(int ints[], int size, int k) so that it returns true if k belongs to ints, otherwise the method should return false. size contains the size of ints. Important note: Try to save CPU...

  • QUESTION: ADT stack: resizable array-based implementation    for Ch4 programming problem 4 "maintain the stacks's top...

    QUESTION: ADT stack: resizable array-based implementation    for Ch4 programming problem 4 "maintain the stacks's top entry at the end of the array" at array index N-1 where the array is currently allocated to hold up to N entries. MAKE SURE YOU IMPLEMENT the functions:  bool isEmpty() const; bool push(const ItemType& newEntry); bool pop(); in ArrayStackP4.cpp //FILE StackInterface.h #ifndef STACK_INTERFACE_ #define STACK_INTERFACE_ template<class ItemType> class StackInterface { public:    /** Sees whether this stack is empty.    @return True if the...

  • c++ please. Write a recursive method that takes the following parameters: * a sorted array of...

    c++ please. Write a recursive method that takes the following parameters: * a sorted array of ints * an int representing the size of the array * an int representing a value to be searched for Your function should return a bool. If the element is in the array, return true. Otherwise, return false. Your function should never produce memory access errors, regardless of the size of the array.

  • using c++ Write a function that returns true if a given integer array is sorted(in ascending...

    using c++ Write a function that returns true if a given integer array is sorted(in ascending order) and false if it is not. The function should perform no more than "size" comparisons. bool isSorted(int A[], int size);

  • Please answer in C++, and Please consider ALL parts of the question, especially where it asks the...

    Please answer in C++, and Please consider ALL parts of the question, especially where it asks the user for V. So there should be a "cin >> V" somewhere. The last guy did not answer it correctly so please make sure you do! Thank You!! Question 1 Write the following two functions. The first function accepts as input a two-dimensional array of integers. It returns two results: the sum of the elements of the array and the average The second...

  • C++ PROGRAMMING Implement a bool function whose header is given below. Inside the function, declare, ask,...

    C++ PROGRAMMING Implement a bool function whose header is given below. Inside the function, declare, ask, and get a character from the user. The function will return true if the character the user enters is NOT in either of the words, otherwise it will return false. Keep in mind that uppercase and lowercase letters are not the same. You will need to change both words and the character input by the user to the same case (upper or lower) -...

  • C ++Write a function, anyThree (int a[], int n), that returns true if the value 3...

    C ++Write a function, anyThree (int a[], int n), that returns true if the value 3 appears in the array exactly 3 times, and no 3's are next to each other. The parameter n will be greater than or equal to 0. Write a function, anyThree (int all, int n), that returns true if the value 3 appears in the array exactly 3 times, and no 3's are next to each other. The parameter n will be greater than or...

  • Given an array of strings, return true if each string's size is equal or greater than...

    Given an array of strings, return true if each string's size is equal or greater than the one before, otherwise return false. The array will be length 2 or more. Example 1: If the names array contains… “Edwin” “Satish” “Solomon” “Massoud” …then the function call stringsIncreasing (names, 4) returns true. Example 2: If the names array contains… “Janet” “Linda” “Jackie” “Marta” …then the function call stringsIncreasing (names, 4) returns false since string Jackie comes before Marta and has more letters...

  • Please use python 3 programming language Write a function that gets a string representing a file...

    Please use python 3 programming language Write a function that gets a string representing a file name and a list. The function writes the content of the list to the file. Each item in the list is written on one line. Name the function WriteList. If all goes well the function returns true, otherwise it returns false. Write another function, RandomRange that takes an integer then it returns a list of length n, where n is an integer passed as...

  • Write the C module intSet to implement an unordered set of integers according to the specification...

    Write the C module intSet to implement an unordered set of integers according to the specification given below. File intSet.h (downloadable off the class web pages): #ifndef INTSET_H #define INTSET_H typedef struct intsetType *intSet; intSet createSet(); // returns an intSet created at runtime using malloc void destroySet(intSet); // frees up the memory associated with its argument void clear(intSet); // clears set to empty (freeing any memory if necessary) int card(const intSet); // returns the cardinality of the set bool equals(const...

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