Monday, 15 February 2010

drawing two consecutive triangle in c -



drawing two consecutive triangle in c -

take 2 base of operations length input , draw 2 triangles in consecutive, rest drawing 2 triangles in consecutive 2 inputs of base of operations length of triangles. code works 1 triangle (spaces filled . clarity).

#include <stdio.h> int main() { int x,sum=1,i,a,b,z; scanf("%d", &x); z=x; for(i=0;i<x;i++) {if (sum>x) break; (b=1;b<z;b++) printf(" "); z=z-1; (a=1;a<=sum;a++) printf("*"); printf("\n"); sum=sum+2; } homecoming 0; }

this outputs

....................* ...................*** ..................***** .................******* ................********* ...............*********** ..............************* .............*************** ............***************** ...........******************* ..........*********************

and expected output input of 7 , 21 is:

.................*.......... ................***......... ...............*****........ ..............*******....... .............*********...... ............***********..... ...........*************.... ...*......***************... ..***....*****************.. .*****..*******************. ****************************

#include <stdio.h> #include <string.h> int main(void){ int n; int small, big; printf("input length of total: "); scanf("%d", &n);//check omit, 2 input ? your's one. little = n / 4; big = little * 3; int total = little + big; int height = (big - 1) / 2 + 1; char canvas[height][total]; memset(canvas, '0', sizeof(canvas)); int i, v, h; for(i=0, v = height; i<height; ++i){ int len; --v; len = little - * 2; if(len > 0) memset(&canvas[v][i], '*', len); len = big - * 2; if(len > 0) memset(&canvas[v][small + i], '*', len); } putchar('\n'); for(v = 0; v < height; ++v){ for(h = 0; h < total; ++h) putchar(canvas[v][h]); putchar('\n'); } homecoming 0; }

c

No comments:

Post a Comment