Friday, 6 February 2015

pattern program 1

1 3*2 4*5*6 10*9*8*7 11*12*13*14*15 #include <stdio.h> int draw_line(int flag,int val,int count) { int i,k; if(!flag) { for (i=0,k=val ;i< count-1;i++ ) { printf("%d*",k); k++; } printf("%d\n",k); return k; } else { int hval=val+count-1; for (i=0,k=hval;i<count-1;i++,k--) { printf("%d*",k); } printf("%d\n",k); return hval; } } int draw_pattern(int n) { int r; if(n==1) { printf("%d\n",n); return n; } r=draw_pattern(n-1); if(n%2) return draw_line(0,r+1,n); else return draw_line(1,r+1,n); } void main() { draw_pattern(6); }

No comments:

Post a Comment