User Defined Functions In C Language 0 792

User Defined Functions In C Language 0 793

 User Defined Functions

Functions defined by us are known as User Defined Functions.

main( ) function is also user defined function because the definition of main( ) is defined by us.

E.g.

int power(int, int);

main( )

{

int n, p, ans;

printf(“Enter number and its power”);

scanf(“%d%d”, &n,&p);

ans = power(n,p);

printf(“%d”,ans);

getch( );

}

int power(int n, int p)

{

in ans=1, i;

for(i=1;i<=p;i++)

{

ans = ans * n;

}

return(ans);

}

Function whose argument is a two dim array

void mat_sum(int m1[][10], int r1, int c1, int m2[][10], int r2, int c2, int m3[][10])

{

int i,j;

if(r1 != c1 && r2 !=c2)

{

printf(“Can’t sum”);

exit( );

}

for(i=0;j<r1;i++)

for(j=0;j<c1;j++)

m3[i][j] = m1[i][j] + m2[i][j];

}

The above function can be called from main( )as mat_sum(m1,r1,c1,m2,r2,c2,m3);

Previous ArticleNext Article
Indian Mirchi will serve you taste in Indian news, general knowledge and information. Hope you like the story I write here and expect your points of discussion to improve them and give the best chili test out of the story. I will write tutorials also that helps students. In case you are looking for any specific information then share me in the comment.

Send this to a friend