Triangle Pattern - 002
Given an odd integer N, print a triangle with * as mentioned in the below examples.
Input Format:
The first line contains N.
Output Format:
N/2 + 1 lines containing the triangle pattern as shown in the example input/output.
Boundary Conditions:
1 <= N <= 999
Example Input/Output 1:
Input:
5
Output:
!!*!!
!***!
*****
Example Input/Output 2:
Input Format:
The first line contains N.
Output Format:
N/2 + 1 lines containing the triangle pattern as shown in the example input/output.
Boundary Conditions:
1 <= N <= 999
Example Input/Output 1:
Input:
5
Output:
!!*!!
!***!
*****
Example Input/Output 2:
Input:
9
Output:
!!!!*!!!!
!!!***!!!
!!*****!!
!*******!
9
Output:
!!!!*!!!!
!!!***!!!
!!*****!!
!*******!
*********
Code:
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
int n,x,y,i,j;
cin>>n;
x=n/2;
y=x;
for(i=0;i<n/2+1;i++)
{
for(j=0;j<n;j++)
{
if(j>=x&&j<=y)
cout<<"*";
else
cout<<"!";
}
x--;y++;
cout<<"\n";
}
}
Please do comment If u have any Queries!
No comments:
Post a Comment