Skip to content

Commit 988b9fe

Browse files
committed
solved 15_PatterChallenge
1 parent 787cbea commit 988b9fe

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
2+
/*******************************************************************************************************
3+
/* ___ _ _ _ _
4+
/* / _ \ | | (_)| | | |
5+
/* / /_\ \__ __ ___ | | __ _ ___ _ __ _ | |_ | |__ _ __ ___ ___
6+
/* | _ |\ \ /\ / / / _ \| | / _` | / _ \ | '__|| || __|| '_ \ | '_ ` _ \ / __|
7+
/* | | | | \ V V / | __/| || (_| || (_) || | | || |_ | | | || | | | | |\__ \
8+
/* \_| |_/ \_/\_/ \___||_| \__, | \___/ |_| |_| \__||_| |_||_| |_| |_||___/
9+
/* __/ |
10+
/* |___/
11+
/******************************************************************************************************/
12+
13+
/***********************************
14+
/* 15_PatternChallenge
15+
/***********************************/
16+
17+
// Library imports
18+
#include <iostream>
19+
#include <cstring>
20+
using namespace std;
21+
22+
//Prototypes for the algorithms
23+
void printPattern_15(char*);
24+
25+
int main(){
26+
// user input
27+
char str[]= "program";
28+
29+
printPattern_15(str);
30+
return 0;
31+
}
32+
33+
/**********************************************************
34+
/* <printPattern_15>
35+
/*
36+
/* @description : print a string pyramid, incremental first, then decremental after reaching the mid point
37+
/* @param : Integer<input>
38+
/* @return : None, void
39+
/* @complexity : O(n)
40+
/* @explanation : We iterate twice the length of string, once the loop reaches mid point(length of the string).
41+
/* One loop in the if block takes care of incrementing the string with every iteration, another
42+
/* for loop to decrement the count to 0, helping to form a decremental pyramid.
43+
/* @author : Pranay Kothapalli @kotAPI
44+
/**********************************************************/
45+
void printPattern_15(char* input){
46+
47+
// Length of the string supplied as an argument to the function
48+
int stringLength = strlen(input);
49+
50+
// Outer loop loops input number of times
51+
for(int i=0;i<stringLength*2;i++){
52+
// if i<mid of the pyramid, that is the length of the string.
53+
if(i<=stringLength){
54+
// Incremental for loop after the mid pyramid for the upper pyramid
55+
for(int j=0;j<i;j++){
56+
cout<<input[j]<<" ";
57+
}
58+
}
59+
// if i > mid of pyramid, thats the string Length
60+
else{
61+
// Decremental for loop for the lower pyramid
62+
for(int j=0;j<2*stringLength - i;j++){
63+
cout<<input[j]<<" ";
64+
}
65+
}
66+
// Add a newline once the inner loops have finished executing.
67+
cout<<endl;
68+
69+
}
70+
71+
72+
73+
74+
75+
76+
}

0 commit comments

Comments
 (0)