Skip to content

Instantly share code, notes, and snippets.

@Indp-Dustin
Created October 4, 2018 07:48
Show Gist options
  • Save Indp-Dustin/182771067088e27b728b13070975fdf3 to your computer and use it in GitHub Desktop.
Save Indp-Dustin/182771067088e27b728b13070975fdf3 to your computer and use it in GitHub Desktop.
diagonal print
#include "pch.h"
#include <iostream>
using namespace std;
const int square = 5;
const int start = 1;
int main()
{
int ystart = start;
for (int y = 0; y < square; y++)
{
int xcurrent = ystart;
cout << xcurrent;
int incx = y;
for (int x = 1; x < square; x++)
{
int incx = x + y;
if (incx >= square)
{
incx = (square * 2 - 1) - incx;
}
xcurrent += incx;
cout << xcurrent;
if (x == 1)
{
ystart = xcurrent + 1;
}
}
cout << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment