Wednesday, August 15, 2012

Right Angle Triangle Program's concept using * and only Single loop

OutPut :-

*
* *
* * *
* * * *

Code:-

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