We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
int n;
scanf("%d", &n);
// Complete the code to print the pattern.
int min = 0;
for (int i = 1; i <= 2 * n - 1; i++)
{
for (int j = 1; j <= 2 * n - 1; j++)
{
int a = i;
if (i > n)
a = 2 * n - i;
int b = j;
if (b > n)
b = 2 * n - j;
if (a < b)
min = a;
else
min = b;
Printing Pattern Using Loops
You are viewing a single comment's thread. Return to all comments →
include
include
include
include
int main() {
int min = 0; for (int i = 1; i <= 2 * n - 1; i++) { for (int j = 1; j <= 2 * n - 1; j++) { int a = i; if (i > n) a = 2 * n - i; int b = j; if (b > n) b = 2 * n - j; if (a < b) min = a; else min = b;
}