I want to print pattern of numbers using c program -
if n=3,the output
1*2*3 7*8*9 4*5*6
if n=5,the output
1*2*3*4*5 11*12*13*14*15 21*22*23*24*25 16*17*18*19*20 6*7*8*9*10
code:
int i,j,a[50][50],k=1,m=0; for(i=0;i<n;i+=2) { for(j=0;j<n;j++) { a[i][j]=k; k++; } printf("\n"); } m=k; for(i=1;i<=n;i+=2) { for(j=0;j<n;j++) { a[i][j]=m; m++; } printf("\n"); } for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%d",a[i][j]); } printf("\n"); }
i not in c language, think you. please have look, , can making change if syntax error occurs logic clear.
#include <stdio.h> #include <math.h> void printoutput(int n){ int k = ceil(n/2); int m =1; int j =1; int l =k; int i; int b; for(i=1;i<=n;i++){ for(b=m;b<=m+n;b++){ printf(b); } printf("\n"); if(i<k){ j= (2*j); m =n*j+1; } else{ int z = n-i-1; m= n+1 +n*(2)*z; l =z-2; } } } void main(){ int input; printf("enter value : "); scanf(" %d",&input); printoutput(input); }
Comments
Post a Comment