Thursday, October 18, 2012

* and _ right angle triangle shape With loops and conditions

OutPut:-
*
_*
*_*
_*_*
*_*_*
_*_*
*_*
_*
*
 
Code :-
 
#include<stdio.h>
void main() {
    int x,n,i,j;
    printf("Enter No of lines to be printed");
    scanf("%d",&n);
    printf("\n");
    for(i=0;i<n;i++) {
          for(j=0;j<=i;j++) {
            if((j+i)%2 == 0)
            printf("*");
            else
            printf("_");
        }
        printf("\n");
    }
    for(i=0;i<n;i++) {
          for(j=n-1;j>i;j--) {
            if((j+i)%2 == 1)
            printf("*");
            else
            printf("_");      
        }
        printf("\n");
    }
    printf("\n");
}

No comments:

Post a Comment