I have done a lot to it since i last came here for help.
But now i have a REAL RULE!!!!! but it's very complicated to explain.
What you will want to do is get a piece of graph paper (and a calculator). Start in the middle, top of the paper (while leaving a row) and place a 1 in the square. Now pretend that all the blanks are 0's, but dont put any anywhere. Now go strait down once and add, (0+1=1) then start back at the original 1 and add diagonally (down 1, over left 1) (0+1=1). Now do the same for the other side diagonal (down 1, over right 1), (0+1=1). Now go back to the top, and add along that diagonal into the blank square. Then go to the blank next to the one you just added (right 1), and look up 1, there should be a 1. Now look at the 2 diagonals, there should be another 1, and a blank. Add these 3 values (1+1+0=2) into that blank square. Now go to the blank square next to that (over right 1). Look vertically, there should be a 1, and another 1 above that. Then look at the 2 diagonals, there should be a 1 on upper left and upper right. Now add ALL those values (1+1+1+1=4). Then go to the next blank square, and the next one, and the next one...
For all you math geeks out there (me included), its basically adding all the values verticaly, all the values in left diagonal and all the values right diagonal.
so what should happen is this:
Quote
1 1 1
2 2 4 2 2
4 5 10 10 10 5 4
8 12 26 30 40 30 26 12 8
except square... dang forum system. oh well.
now here is the programming question.
How do i make it so that i get that form of addition automatically for much much much much longer, around 100 rows or more.
right now im going to start with a matrix that is 6x11 (I already build did this size of matrix on paper... twice...)
I was thinking for() loops, but im not sure.
Here is the current code:
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstdio>
#include <fstream>
using namespace std;
//Variables
int row; //Used for placing rows in matrix
int col; //col number
int next; //used as another portion to the rule
int row_size = 6 //numbers of rows ( -- )
int col_size = 11 //Number or colums ( | )
int matrix[row_size][row_size]; //Matrix, row_size x col_size
// Functions
void txtclr() //Text Clear, used to clear the out file before the next print
{
ofstream UM("Out.txt", ios::out); //Opens "Out.txt" for clean, overwriting
}
void rule()
{
//Here is where the Matrix addition code will be
}
void txtprnt() //Text Print, prints out the data from rule() to a file
{
rule(); //Runs the Rule
ofstream UM("Out.txt", ios::out | ios::app); //Dump arrays onto "Out.txt" at end of
for( row = 0; row != row_size; row++) //Used to advance to next row once the first row is completed
{
UM << "|"; //Visual Character
cout << "|"; //View Real time generation
for( col = 0; col != col_size; col++ ) //Matrix Colum Builder
{
UM << matrix[row][col] << "|"; //Print the number in the space [row]x[col], and a Visual Character
cout << matrix[row][col] << "|"; //View Real time generation
}
UM << '\n'; //once row completed, move down a line
cout << '\n'; //View Real time generation
}
}
//Program
int main(int argc, char *argv[])
{
txtclr(); //Clear text
txtprnt(); //Print text [Generate numbers]
return 0;
}
This post has been edited by haun: 12 January 2009 - 11:44 PM

Help



Back to top











