Write a recursive function that generates this pattern XXXX
Solution
//code has been tested on gcc compiler
#include <iostream>
using namespace std;
 void printPatterns(int longestline,char pattern)
 {
 if (longestline < 0) cout << endl << \"Please enter a positive number greater than 0\" << endl;
  
 else{
 if (longestline == 0) return; //base case
else{
 for (int i = 1; i <= longestline; i++) //for printing upper part
 {cout <<pattern ;}   
 cout << endl;
printPatterns(longestline - 1,pattern); //calling function recursively
 if(longestline!=1) //does not need to print 1 pattern again
 { for (int i = 1; i <= longestline; i++) //forprinting lower part
 {cout << pattern;}
cout << endl;}
 }
   
 }
 }
 //end of method
int main()
 {
 
 printPatterns(4,\'X\'); //calling function with parameters,longestline=4 and pattern=X
 return 0;
 }
//end of code
********OUTPUT***********
XXXX
XXX
XX
X
XX
XXX
XXXX
********OUTPUT***********
Note:As you have not described any specific language i have done this in c++,please let me know in case of any doubt,thanks.


