Skip to content

Commit 11788ee

Browse files
committed
solved 17_PatternChallenge
1 parent 2353fee commit 11788ee

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
2+
/*******************************************************************************************************
3+
/* ___ _ _ _ _
4+
/* / _ \ | | (_)| | | |
5+
/* / /_\ \__ __ ___ | | __ _ ___ _ __ _ | |_ | |__ _ __ ___ ___
6+
/* | _ |\ \ /\ / / / _ \| | / _` | / _ \ | '__|| || __|| '_ \ | '_ ` _ \ / __|
7+
/* | | | | \ V V / | __/| || (_| || (_) || | | || |_ | | | || | | | | |\__ \
8+
/* \_| |_/ \_/\_/ \___||_| \__, | \___/ |_| |_| \__||_| |_||_| |_| |_||___/
9+
/* __/ |
10+
/* |___/
11+
/******************************************************************************************************/
12+
13+
/***********************************
14+
/* 17_PatternChallenge
15+
/***********************************/
16+
17+
// Library imports
18+
#include <iostream>
19+
using namespace std;
20+
21+
//Prototypes for the algorithms
22+
void printPattern_17(int);
23+
24+
int main(){
25+
// user input
26+
int userInput;
27+
28+
cout<<"Enter number of lines."<<endl;
29+
cin>>userInput;
30+
31+
printPattern_17(userInput);
32+
return 0;
33+
}
34+
35+
/**********************************************************
36+
/* <printPattern_17>
37+
/*
38+
/* @description : Algorithm to print alternating increasing and decreasing * lines.
39+
/* @param : Integer<input>
40+
/* @return : None, void
41+
/* @complexity : O(n)
42+
/* @explanation : Algortihm that takes input from the user and prints increasing and decreasing star lines in alternate
43+
/* lines. The outer loop iterates 'input' number of times. The first inner loop takes care of decreasing
44+
/* the star lines. The second innner loop takes care of increasing the star lines. These execute alternatingly
45+
/* one after another in every outer loop iteration.
46+
/* @author : Pranay Kothapalli @kotAPI
47+
/**********************************************************/
48+
void printPattern_17(int input){
49+
50+
// Outer
51+
for(int i=0;i<input;i++){
52+
53+
//Inner loop to print the decreasing star lines depending on value of 'i'
54+
for(int k=0;k<i;k++){
55+
cout<<"*";
56+
}
57+
// Inner loop to print the increasing star lines depending on 'input-i'.
58+
cout<<endl;
59+
for(int j=0;j<input-i;j++){
60+
cout<< "*";
61+
}
62+
63+
// Add a newline once the inner loops have finished executing.
64+
cout<<endl;
65+
}
66+
67+
}

0 commit comments

Comments
 (0)