Posts

Showing posts from June, 2015

Program to pass 2D array in a function in C

#include<stdio.h> void func(int a[][10],int k,int l) { int i,j; for(i=0;i<k;i++) { for(j=0;j<l;j++) { printf("%d",a[i][j]); } printf("\n"); } } int main() { int ar[10][10],n,i,m,j; printf("Enter the row & column of the matrix"); scanf("%d %d",&m,&n); //ar=(int *)calloc(m,sizeof(int)); for(i=0;i<m;i++) { //*ar=(int *)calloc(n,sizeof(int)); for(j=0;j<n;j++) { scanf("%d",&ar[i][j]); } } func(ar,m,n); } O/P: Enter the row & column of the matrix: 4 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1234 1234 1234 1234 after taking 16 values it will just print them in matrix form .....