Write a program to print a triangle.
Example:
** ** * ** * * ** * * * *
Approach:
Java
public class TringlePrint {public static void main(String[] args) {int n = 5;for (int i = 0; i < n; i++) {for (int j = 0; j <=i; 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<=i;j++)cout<<"* ";cout<<"\n";}return 0;}
No comments:
Post a Comment