Write a program to print the following pattern.
Example:
* * * * ** * * * ** * * * ** * * * ** * * * *
Approach:
Java
public class StarSquarePrint {public static void main(String[] args) {int n = 5;int m = 5;for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++) {System.out.print("* ");}System.out.println();}}}
C++
#include <bits/stdc++.h>using namespace std;int main(){int n=5,m=5;for(int i=1;i<=n;i++){for(int j=1;j<=m;j++)cout<<"*";cout<<"\n";}return 0;}
No comments:
Post a Comment