hw8p1.c - \/Kyle Yamamoto\/This program checks a file for if it is a solution to a sudoku#define_CRT_SECURE_NO_WARNINGS#include<stdio.h> int

hw8p1.c - /Kyle Yamamoto/This program checks a file for...

  • Homework Help
  • captain0cat
  • 3
  • 100% (3) 3 out of 3 people found this document helpful

This preview shows page 1 - 2 out of 3 pages.

//Kyle Yamamoto //9-15-2014 //This program checks a file for if it is a solution to a sudoku #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> int check_line(int board[9][9], int i, int j) { //Function to check the rows and columns int num = 0, a = 0, b = 0; for (i = 0; i < 9; i++) { //For loop to go through each line for (j = 0; j < 9; j++) { //For loop to go through each position in the line num += board[a][b]; //Adds up the total a++; } if (num != 45) { //Checks the total return 1; } num = 0; //Resets the total back to zero b++; //Using b as a variable for the second part of the array a = 0; //Using a as a variable for the first part of the array } return 0; //Returns 0 if the rows or columns are solutions } int check_square(int board[9][9]) { //Function to check the squares int a = 0, b = 0, i = 0, j = 0, num[81] = {0}, total = 0; for (i = 0; i < 9; i++) { //For loop to put numbers in a long 1-Dimensional array for (j = 0; j < 9; j++) { num[a] = board[i][j]; a++; } } i = 0; j = 0; for (a = 0; a < 9; a++) { //For loop to go through each instance of a square while (j < 3) { //While to add the three columns in the square total += num[i] + num[i + 1] + num[i + 2]; //Adds the three rows in the square
Image of page 1
Image of page 2

You've reached the end of your free preview.

Want to read all 3 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture