# Thread: Number Patterns are killing me.

1. ## Number Patterns are killing me.

For a programming homework assignment, we are using nested loops to create number patterns, I thought i was pretty good at this, but these problems are killing me because I cannot figure out the formula to get the start values.

The patterns are these:
the first
5 7 9 11 10 8 6 4
3 6 9 8 5 2
2 6 5 1

the second
10 8 6 4 5 7 9 11
8 5 2 3 6 9
5 1 2 6

third
2 6 5 1
3 6 9 8 5 2
5 7 9 11 10 8 6 4

fourth
5 1 2 6
8 5 2 3 6 9
10 8 6 4 5 7 9 11

I have everything but the start values figured out for instance the second one my program looks like this.
Code:
```//Inner Loop 1 - right hand pattern
//Start Value:  THIS IS WHAT I CAN'T FIGURE OUT on any of them.
//Number of iterations: 5 - row

//Inner Loop 2 - left hand pattern
//Start Value: number + row + 2
//Number of iterations:  5 - row

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

int main()
{
int row, col, number;

for (row = 1; row <= 3; row++)
{
number = THIS IS WHAT I CAN'T FIGURE OUT;
for (col = 1; col <= 5 - row; col++)
{
//Display correct number
cout << setw(5) << number;

number -= row - 1;
} //End col loop

number = number + row + 2;
for (col = 1; col <= 5 - row; col++)
{
//Display correct number
cout << setw (5) << number;

number += row + 1;
}//end column loop
cout << endl;
}  //End row loop
return 0;
}```

2. I know u can solve them but u don't want to do so ...
btw i tried 1st and code is below..
Code:
```#include<iostream>
using namespace std;
int main()
{
int i,var,num,j,fix=5;
var =4;
for(i=1;i<=3;i++)
{
num=fix;
for(j=1;j<=var;j++)
{
cout<<num<<" ";
num+=(i+1);
}
num-=(i+1);
for(j=1;j<=var;j++)
{
num--;
cout<<num<<" ";
num-=(i);
}
cout<<endl;
var-=1;
fix=fix-(3-i);

}
return 0;
}```

`int startNumbers[3] = { 5, 3, 2 };`
```    for ( i = 0 ; i < 3 ; i++ ) {