Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8126585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:11:59+00:00 2026-06-06T07:11:59+00:00

I have been staring at this code for few hours, tried walkthrough,debugging with autos

  • 0

I have been staring at this code for few hours, tried walkthrough,debugging with autos and breakpoints and it’s no solution so far. Maybie someone’s fresh look would help me 😉 .

#include <iostream>

using namespace std;

int matrix[9][9] = {{0, 0, 6, 0, 0, 0, 1, 0, 5},
                    {0, 4, 0, 7, 0, 6, 0, 3, 9},
                    {2, 0, 0, 9, 3, 0, 6, 0, 0},
                    {7, 0, 0, 1, 8, 0, 5, 0, 4},
                    {0, 0, 4, 0, 6, 0, 9, 0, 0},
                    {1, 0, 9, 0, 5, 2, 0, 0, 3},
                    {0, 0, 1, 0, 9, 3, 0, 0, 7},
                    {6, 7, 0, 5, 0, 8, 0, 9, 0},
                    {9, 0, 8, 0, 0, 0, 4, 0, 0}};


bool check(int column  ,int row,int checkedValue) 
{
    //column check
    for(int i=0; i<9; i++) 
    {       
        if(i==row)continue;

        if(checkedValue==matrix[column][i]) return false;
    }
    //row check 
    for(int i=0; i<9; i++) 
    {   
        if(i==column) continue;
        if(checkedValue==matrix[i][row]) return false;
    }                       
        return true;
}   



int main()
{
    cout<<check(4,0,4); //Why does it output 0? There is no "4" in the 5th column and the 1st row.

    system("pause");
    return 0;
}

The function check(column,row,value) was designed to return 0 when number occurs at least once in the “matrix” two dimensional table. This program is a chunk of sudoku solver.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:12:01+00:00Added an answer on June 6, 2026 at 7:12 am

    You mixed the indices up in the if statements. They should be:

    if(checkedValue==matrix[i][column]) return false; // not matrix[column][i]
    

    and

    if(checkedValue==matrix[row][i]) return false;    // not matrix[i][row]
    

    The reason is that the first dimension is the row. You can check this by printing matrix[2][0].
    For your matrix, you will get 2 (and not 6).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been struggling with this problem for the last few hours, and it
I have been banging my head on this for a few hours and google
Now I do have a hw question for everyone...I've been staring at this for
I have been using this so far system 'strings binary-file.dmp | grep search_string' Is
I've been stuck with diagnosing this for a few hours now and thought I'd
I have been messing around with recursion a few hours and just cant get
So I have been stuck for a couple of hours trying to get this
I've been stuck at this problem for a few hours now. I've commented out
I have been learning python for some time now. While starting this learning python
I have been passed a date string that looks like this: Thu%20Mar%2011%202010%2015%3A09%3A11%20GMT%2B0000%20(BST) I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.