Professional Documents
Culture Documents
FUNCTIONS
What is a function?
message()
{
printf("Smile, and the world smiles with you ");
}
Explanation:-
Ex:-
message()
{
printf("Smile, and the world smiles with you ");
}
italy()
{
printf("\n Italy is country of culture and arts. ");
}
argentina ()
{
printf(" we r in argentina.");
}
any function can be called any number of times.
The order in which the functions are defined and the order in which
they get called need not necessarily be same. For example:-
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("Intially we r in the main function.\n");
message(); Intially we r in the main function.
italy();
printf("\nBye bye"); Be happy
getch(); Italy is a city of art and cultutre
}
italy()
{
printf("\n Italy is a city of art and cultutre");
}
message()
{
printf("\n Be happy");
}
Ex:- write a program that takes two integer as inputs and calculates
the sum of them through a called /( user defined) function and returns
the returns the result from that function.
#include<stdio.h>
#include<conio.h>
void main()
{ int a,b,c;
clrscr();
printf("Intially we r in the main function.");
message(); Intially we r in the main function.
printf("\nEnter the numbers\n"); Be happy
scanf("%d %d", &a, &b); Enter the numbers
c=sum(a,b); 5
printf("\n so, the result is %d", c); 10
printf("\nBye bye"); Italy is a city of art and culture
getch(); so, the result is 15
} Bye bye
message()
{
printf("\n Be happy");
}
italy()
{
printf("\n Italy is a city of art and culture");
}
int sum(int x, int y)
{ int z;
z=x+y;
italy();
return c;
}
Here from the main() function the passed values are a and b to the
argument x and to the argument y of the user defined function sum(int
x, int y). And the returned value is z from the user defined function
sum(…) to the calling function main(). And the returned value is
received by the variable c.
so, *area=*(4002)=3.14*5*5=78.500000
*perimeter=*(4006)=2*3.14*5=31.400000