I have to write a program that needs to print out gray code based on the amount of columns the user wants. For example if they choose three, I have 8 rows with gray code from 0 to 7.
I need help with the algorithm that I need to use. I have to use for loops and they must be contained within the main function.
#include <iostream>
#include <cmath>
usingnamespace std;
int main()
{
int i, j;
int num = 4;
int numberOfRows = pow(2,num);
for (int i = 0; (i < numberOfRows); i++)
{
for (int j=0; (j < num); j++)
{
if ((j % num / pow(2,num)) < (num /(pow(2,num)+1)))
cout << "0\t";
else
cout << "1\t";
}
cout<<"\n";
}
return 0;
}