Question
please use c++
• Prompt the user for elements of an integer matrixs (mXn) that includes numbers from 0 to 9 (m>=3 n>=3, you are free to def
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
using namespace std;
const int m = 5;
const int n = 4;
bool checker(int arr[][n],int m,int n)
{
   int i,j,ele;
   for(i=0;i<m;i++)
   {
       for(j=0;j<n;j++)
       {
           ele=arr[i][j];
           for(int p=i-1;p<=i+1;p++)
           {
               if(p<0||j-1<0||p>m-1||j-1>n-1)
                {
                   continue;
               }
              if(ele==arr[p][j-1])
                  return false;  
              
           }
           for(int p=i-1;p<=i+1;p++)
           {
               if(p<0||j+1<0||p>m-1||j+1>n-1)
               {
                   continue;
               }
          
               if(ele==arr[p][j+1])
                    return false;
          
           }
           if(i-1<0||i-1>m||i+1<0||i+1>m)
              continue;
           else
           {
               if(ele==arr[i-1][j])
                  return false;
                  if(ele==arr[i+1][j])
                    return false;
              }
          
       }
   }
  
return true;  
}  

int main()
{
   int arr[m][n];
   cout<<"Enter the matrix element(element lio on 0-9):\n";
   for(int i=0;i<m;i++)
   {
       for(int j=0;j<n;j++)
          cin>>arr[i][j];
   }
   cout<<"Output:\n";
   bool p=checker(arr,m,n);
   if(p==1)
      cout<<"True";
   else
       cout<<"False";
   return 0;      
}

OUTPUT:-

Enter the matrix element(element lio on 0-9):
0 1 2 6
3 4 5 7
6 7 8 9
9 0 1 3
2 3 4 2
Output:
True

Enter the matrix element(element lio on 0-9):
0 1 2 6
3 4 1 7
6 7 8 9
9 0 1 3
2 3 4 2
Output:
False

Add a comment
Know the answer?
Add Answer to:
please use c++ • Prompt the user for elements of an integer matrix's (mXn) that includes...
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
  • c++ please (1) Write a program that prompts the user to enter an integer value N...

    c++ please (1) Write a program that prompts the user to enter an integer value N which will rpresent the parameter to be sent to a function. Use the format below. Then write a function named CubicRoot The function will receive the parameter N and return'its cubic value. In the main program print the message: (30 Points) Enter an integer N: [. ..1 The cubic root of I.. ] is 2 update the code om part and write another function...

  • Please help i need a C++ version of this code and keep getting java versions. Please...

    Please help i need a C++ version of this code and keep getting java versions. Please C++ only Purpose: This lab will give you experience harnessing an existing backtracking algorithm for the eight queens problem, and seeing its results displayed on your console window (that is, the location of standard output). Lab A mostly complete version of the eight queens problem has been provided for you to download. This version has the class Queens nearly completed. You are to provide...

  • PLEASE COMPLETE IN C++ LANGUAGE Location row : int = -1 col : int = -1...

    PLEASE COMPLETE IN C++ LANGUAGE Location row : int = -1 col : int = -1 setLocation(row : int, col : int) getRow(): int getColl): int isEmpty(): bool Details Write all the code necessary to implement the Location class as shown in the UML Class Diagram to the right. Do this in a project named snake (we'll continue adding files to this project as the term progresses). Your class definition and implementation should be in separate files. When complete, you...

  • PYHTON CODING FUNCTIONS HELP Part 2. Also need help with these last functions. Requirements/restraints and the...

    PYHTON CODING FUNCTIONS HELP Part 2. Also need help with these last functions. Requirements/restraints and the map referred to is pictured in the screenshot. Need help with these 4 tasks: Function 4: def is_map(map) : given a map (see screenshot), does it meet the following criteria? 1) it is a list of lists of values of type int; 2) it has at least one row and one column; 3) it’s rectangular (all sub-lists are same length); 4) only non-negative ints...

  • In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand....

    In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand. Do not write "#include" and do not write whole "main()" function. Write only the minimal necessary code to accomplish the required task.                                                                                                           Save your answer file with the name: "FinalA.txt" 1) (2 pts) Given this loop                                                                                              int cnt = 1;     do {     cnt += 3;     } while (cnt < 25);     cout << cnt; It runs ________ times    ...

  • IN C++ PLEASE -------Add code to sort the bowlers. You have to sort their parallel data...

    IN C++ PLEASE -------Add code to sort the bowlers. You have to sort their parallel data also. Print the sorted bowlers and all their info . You can use a bubble sort or a shell sort. Make sure to adjust your code depending on whether or not you put data starting in row zero or row one. Sort by Average across, lowest to highest. The highest average should then be on the last row.. When you sort the average, you...

  • c++ help please! Create a 2D character array in your main function and use nested for...

    c++ help please! Create a 2D character array in your main function and use nested for loops to fill the array with the letter ‘e’ to represent empty spaces. Create a function to print the board on the screen using a nested for loop. The function header is: void printBoard (char board [][3]) Create a function that checks whether a particular space has already been filled. If the space is filled it returns a boolean value of true, otherwise false....

  • C++ Modify this program (or create your own) so that it performs the following tasks: 1....

    C++ Modify this program (or create your own) so that it performs the following tasks: 1. Insert the numbers into the list in sorted order (ascending). This will require you to keep the list sorted as you continue to insert new numbers. 2. When adding a new number, first check to see whether it is larger than the last number currently in the list. If it is, add it directly to the end of the list, i.e., do not traverse...

  • PLEASE HURRY. Below is the prompt for this problem. Use the code for bag1.cxx, bag1.h and...

    PLEASE HURRY. Below is the prompt for this problem. Use the code for bag1.cxx, bag1.h and my code for bag.cpp. Also I have provided errors from linux for bag.cpp. Please use that code and fix my errors please. Thank you The goal of assignment 3 is to reinforce implementation of container class concepts in C++. Specifically, the assignment is to do problem 3.5 on page 149 of the text. You need to implement the set operations union, intersection, and relative...

  • Please I need help in C language, I am trying to modify the code per the...

    Please I need help in C language, I am trying to modify the code per the below instructions, but I am getting errors. Can't fgure it out. The attempted code modification and data file is privided below, after the instructions. Thank you. Instructions:                  1.      First, add a function named printMsg that displays a message, a greeting, or an introduction to the program for the user. Add a statement that calls that function from the main function when your program starts....

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