Functions
#include <stdio.h>
// function prototypes
int my_addition(int a, int b);
int my_multiplication(int c, int d);
int my_square(int n);
void my_print(int x, int y, int z);
int main()
{
int x = 1;
int y = 2;
// call the user-defined function my_addition(...)
int sum = my_addition(x, y);
// call the user-defined function my_multiplication(...)
int product = my_multiplication(x, y);
// use the user-defined function my_square(...)
int square = my_square(x);
// use the user-defined procedure my_print(...)
my_print(sum, product, square);
return 0;
}
// A function
int my_addition(int a, int b)
{
return a + b;
}
// Another function
int my_multiplication(int c, int d)
{
return c * d;
}
// Yet another function which calls some function
int my_square(int n)
{
return my_multiplication(n, n);
}
// A procedure
void my_print(int x, int y, int z)
{
printf("Now behold my super printing function!\n");
printf("x = %d, y = %d, z = %d\n", x, y, z);
printf("As you can see, it is completely useless,\n");
printf("without printf it can do nothing!\n");
}
Last modified: Wednesday, 13 November 2024, 8:50 AM