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:
9
Output:
!!!!*!!!!
!!!***!!!
!!*****!!
!*******!
*********
C code:
#include<stdio.h>
#include <stdlib.h>
int main()
{
int n,i,j;
scanf("%d",&n);
for(i=0;i<n/2+1;i++)
{
for(j=0;j<n/2-i;j++)
printf("!");
for(j=0;j<i*2+1;j++)
printf("*");
for(j=0;j<n/2-i;j++)
printf("!");
printf("\n");
}
}
No comments:
Post a Comment