Pattern Series
Pattern Series
Pattern-1:-
R/ 0 1 2 3 4
C
0 * * * * *
1 * * * * *
2 * * * * *
3 * * * * *
4 * * * * *
Algorithm:-
Step-1:-Initiate the rows and columns and an integer n, so that no. of rows
and no. of columns can be changed easily.
Step-2:-the logic behind the above pattern is that in all rows and all
columns * is present.
Step-3:-Use two for loops (one inside the other), so that we can print the
above series.
Program in C:-
#include <stdio.h>
int main()
{
int i, j, n=5;
for(i = 0; i < n; i++){
for(j = 0; j < n; j++){
printf("*");
Different Pattern Series Comparison in C and Java
}
printf("\n");
}
}
/*Save it as pattern1.c*/
Program in Java:-
class Demo
{
public static void main(String[] args) {
int n=5;
for (int i=0; i<n; i++){
for (int j=0; j<n; j++){
System.out.print("*");
}
System.out.println(" ");
}
}
}
/*Save it as Demo.java*/
/* always save as class name*/
Different Pattern Series Comparison in C and Java