
Introduction
Computer programmers must possess a diverse set of abilities in order to carry out the position's various obligations with the utmost expertise. Knowledge, aptitude, and technical competency are combined with soft skills such as the ability to work as part of a team and communicate well with others by the most effective programmers. Both sorts of talents must be demonstrated by aspiring computer programmers.
This article will help you improve your technical skills.
In this blog, we will learn how to print the following pattern in different programming languages.
Approach
For printing the following pattern, we will use two loops. The upper loop will be to traverse through the row, and the second loop will be to traverse through the column,
1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3 3
4 4 4 4 4 4
5 5 5 5 5 5
6 6 6 6 6 6
Printing pattern in C
The following code illustrates how to print the above pattern in C programming language.
#include<stdio.h>
int main()
{
int n = 6;
for (int i=1;i<=n;i++){
for (int j=0;j<n;j++){
printf("%d ",i);
}
printf("\n");
}
}
Output:
1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3 3
4 4 4 4 4 4
5 5 5 5 5 5
6 6 6 6 6 6
Printing pattern in C++
The following code illustrates how to print the above pattern in C++ programming language.
#include<iostream>
using namespace std;
int main()
{
int n = 6;
for (int i=1;i<=n;i++){
for (int j=0;j<n;j++){
cout<<i<<" ";
}
cout<<endl;
}
}
Output:
1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3 3
4 4 4 4 4 4
5 5 5 5 5 5
6 6 6 6 6 6
Printing pattern in Java
The following code illustrates how to print the above pattern in Java programming language.
public class A {
public static void main(String[] args) {
for (int i=1;i<=6;i++){
for (int j=0;j<6;j++){
System.out.print(i+" ");
}
System.out.println();
}
}
Output:
1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3 3
4 4 4 4 4 4
5 5 5 5 5 5
6 6 6 6 6 6
Printing pattern in Python
The following code illustrates how to print the above pattern in Python programming language.
n = 6
for i in range(1,6+1):
for j in range(6):
print(i,end=" ")
print()
Output:
1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3 3
4 4 4 4 4 4
5 5 5 5 5 5
6 6 6 6 6 6
Also See, Fibonacci Series in Python
Also Read - Strong number in c