Given an integer n. You need to recreate the pattern given below for any value of N. Let's say for N = 5, the pattern should look like as below:
*****
*****
*****
*****
*****
Print the pattern in the function given to you.
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
//Function to print pattren1
void pattern1(int n) {
// Outer loop will run for rows.
for (int i = 0; i < n; i++) {
// Inner loop will run for columns.
for (int j = 0; j < n; j++) {
cout << "*";
}
/* As soon as n stars are printed, move
to the next row and give a line break.*/
cout << endl;
}
}
};
int main() {
int N = 4;
//Create an instance of the Solution class
Solution sol;
sol.pattern1(N);
return 0;
}
class Solution {
// Function to print pattern1
public void pattern1(int n) {
// Outer loop will run for rows.
for (int i = 0; i < n; i++) {
// Inner loop will run for columns.
for (int j = 0; j < n; j++) {
System.out.print("*");
}
/* As soon as n stars are printed, move
to the next row and give a line break. */
System.out.println();
}
}
public static void main(String[] args) {
int N = 4;
// Create an instance of the Solution class
Solution sol = new Solution();
sol.pattern1(N);
}
}
class Solution:
# Function to print pattern1
def pattern1(self, n):
# Outer loop will run for rows.
for i in range(n):
# Inner loop will run for columns.
for j in range(n):
print("*", end="")
""" As soon as N stars are printed, move
to the next row and give a line break."""
print()
def main(self):
N = 4
# Create an instance of the Solution class
sol = Solution()
sol.pattern1(N)
if __name__ == "__main__":
Solution().main()
class Solution {
//Function to print pattern1
pattern1(n) {
//Outer loop which will loop for the rows.
for (let i = 0; i < n; i++) {
// Inner loop will run for columns.
for (let j = 0; j < n; j++) {
process.stdout.write("*");
}
/* As soon as n stars are printed, move
to the next row and give a line break. */
console.log();
}
}
}
const N = 4;
// Create an instance of the Solution class
const sol = new Solution();
sol.pattern1(N);