/*write a c program to generate following output 1 1 1 1 3 1 1 4 4 1 1 3 5 3 1 1 4 6 6 4 1 */ #include<stdio.h> #include<conio.h> void main() { int n,i,j,k=1; clrscr(); printf("n:"); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=n;j>=i;j--) { printf(" "); } for(j=1;j<=i;j++) { if(i%2==0) { if(j==1||j==i) { printf("1 "); } else if(j<i/2) { printf("%d ",k); k=k+2; } else if(j>i/2) { printf("%d ",k); k=k-2; } else { printf("%d ",k); } } else { if(j==1||j==i) { printf("1 "); } else if(j<=i/2) { printf("%d ",k); k=k+2; } else if(j>=i/2) { printf("%d ",k); k=k-2; } else { printf("%d ",k); } } } printf("\n"); if(i%2==0) k=3; else k=4; } getch(); }
write a c program to generate following output 1 1 1 1 3 1 1 4 4 1 1 3 5 3 1 1 4 6 6 4 1
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment