From 0855c390331d2f699eb73dcbfca48ef3226a6d61 Mon Sep 17 00:00:00 2001 From: gurmehakk20 <125135241+gurmehakk20@users.noreply.github.com> Date: Sat, 20 May 2023 19:59:00 +0530 Subject: [PATCH 1/2] Create pattern7.md --- Pattern/pattern7.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 Pattern/pattern7.md diff --git a/Pattern/pattern7.md b/Pattern/pattern7.md new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Pattern/pattern7.md @@ -0,0 +1 @@ + From d9f5afcf2d1652234bbf326764571412e87c3990 Mon Sep 17 00:00:00 2001 From: gurmehakk20 <125135241+gurmehakk20@users.noreply.github.com> Date: Sat, 20 May 2023 20:17:42 +0530 Subject: [PATCH 2/2] Update pattern7.md --- Pattern/pattern7.md | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/Pattern/pattern7.md b/Pattern/pattern7.md index 8b13789..c4162cf 100644 --- a/Pattern/pattern7.md +++ b/Pattern/pattern7.md @@ -1 +1,49 @@ +# Description +In this code, a triangle pattern will be formed using for loop +# Code +``` +#include +using namespace std; + +int main() { + int i, j, n; + cin >> n; + for (i = 1; i <= n; i++) { + int a = i; + for (j = 1; j <= n - i; j++) { + cout << " "; + } + for (j = 1; j <= i; j++) { + cout << a << " "; + a++; + } + for (j = 1; j < i; j++) { + a--; + cout << a - 1 << " "; + } + cout << endl; + } + return 0; +} +``` +# Test Cases +``` +Sample-Test case 1: + +Input: 5 +Output: + 1 + 2 3 2 + 3 4 5 4 3 + 4 5 6 7 6 5 4 +5 6 7 8 9 8 7 6 5 + +Sample-Test case 2: + +Input: 3 +Output: + 1 + 2 3 2 +3 4 5 4 3 +```