Created
October 4, 2018 07:48
-
-
Save Indp-Dustin/182771067088e27b728b13070975fdf3 to your computer and use it in GitHub Desktop.
diagonal print
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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