Friday, 6 February 2015

pattern 4

1 2*2 3*3*3 4*4*4*4 4*4*4*4 3*3*3 2*2 1 #include <stdio.h> void draw_line(int n); void draw_pattern(int n,int m); void draw_rpattern(int n,int m); void main() { draw_pattern(4,4); } void draw_line(int n) { int i; for (i=0;i<n-1;i++ ) { printf("%d*",n); } printf("%d\n",n); } void draw_pattern(int n,int m) { if(n==1) draw_line(n); else { draw_pattern(n-1,m); draw_line(n); if(n==m) draw_rpattern(n,m); } } void draw_rpattern(int n,int m) { if(n==1) draw_line(n); else { draw_line(n); draw_rpattern(n-1,m); } }

No comments:

Post a Comment