If you have any query feel free to chat us!
Happy Coding! Happy Learning!
A "Fancy Pattern - 1" is a pattern that consists of numbers arranged in a specific way to form a symmetrical and visually appealing design. This pattern usually involves a combination of stars, spaces, and numbers. Let's create a "Fancy Pattern - 1" using C++:
Here's the pattern for 5 rows:
markdownCopy code
1 1 2 2 3 3 4 4 5 5 4 4 3 3 2 2 1 1
Let's write a C++ program to generate the "Fancy Pattern - 1" based on the number of rows specified by the user:
cppCopy code
#include <iostream> int main() { int rows; std::cout << "Enter the number of rows: "; std::cin >> rows; // Upper part of the pattern for (int i = 1; i <= rows; i++) { // Print spaces before the first number for (int space = 1; space < i; space++) { std::cout << " "; } // Print the first number and space between two numbers std::cout << i; for (int space = 1; space <= (rows - i) * 2 - 1; space++) { std::cout << " "; } // Print the second number if (i != rows) { std::cout << i; } std::cout << std::endl; } // Lower part of the pattern for (int i = rows - 1; i >= 1; i--) { // Print spaces before the first number for (int space = 1; space < i; space++) { std::cout << " "; } // Print the first number and space between two numbers std::cout << i; for (int space = 1; space <= (rows - i) * 2 - 1; space++) { std::cout << " "; } // Print the second number if (i != rows) { std::cout << i; } std::cout << std::endl; } return 0; }
Example output for
rows = 5
:markdownCopy code
1 1 2 2 3 3 4 4 5 5 4 4 3 3 2 2 1 1
In the code above, we use two nested loops to print the upper and lower parts of the pattern. The outer loop
i
controls the number of rows, and the inner loopspace
prints the spaces before the first number, the first number, the spaces between two numbers, and the second number. The pattern is constructed in such a way that it forms a symmetrical and visually appealing design.Feel free to experiment with different values of
rows
to generate "Fancy Pattern - 1" of different sizes.
I bought this course, it worth it!
Hi i want to buy this course but you dont have master card payment method please let me know how i can buy it
Dear mk.info.work, Now we have all types of payment options. If you need to purchase just checkout our official website
Quick answers to common questions about our courses, quizzes, and learning platform
SCIAKU Team please upload 1st video of TREE please please please, please