Answer to Question #44721 in C++ for jalal

Question #44721
You are given n you are required to print the following rhombus:
----------------------------------------------------------------
Example:5

1
121
12321
1234321
123454321
1234321
12321
121
1
1
Expert's answer
2014-08-11T10:41:47-0400
#include <stdio.h>
#include <stdlib.h>
int main()
{
int N = 5;

// Top part
for (int row = 1; row <= N; row ++)
{
for (int col = 1; col <= N - row; col ++)
printf(" ");
for (int col = 1; col <= row; col ++)
printf("%d", col);
for (int col = row - 1; col >= 1; col --)
printf("%d", col);
printf("\n");
}

// Bottom part
for (int row = N - 1; row >= 1; row --)
{
for (int col = 1; col <= N - row; col ++)
printf(" ");
for (int col = 1; col <= row; col ++)
printf("%d", col);
for (int col = row - 1; col >= 1; col --)
printf("%d", col);
printf("\n");
}

system("pause");
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS