In: Computer Science
Functions
a) C program to create function to calculate multiplying 15 with 6
#include <stdio.h>
//function prototype
multiply(int a,int b);
int main()
{
//calling function multiply-passing 15 and 6
multiply(15,6);
return 0;
}
//function multiply() implementation
multiply(int a, int b)
{
//variable to hold multiplication of two values
int res;
//multiplication of a and b
res = a * b;
//printing result of a multipled by b
printf("Result=%d",res);
}
Output: Result=90
b) C program to create function to double the number 20
#include <stdio.h>
//function prototype
int doubleValue(int x);
int main()
{
//calling function doubleValue-passing 20 and assigning it to
result
int result = doubleValue(20);
//printing result to console
printf("\nResult=%d",result);
return 0;
}
//function doubleValue() implementation
int doubleValue(int a)
{
//variable declaration
int myResults;
//double the number
myResults = 2 * a;
//Have it return to myResults
return myResults;
}
Output: Result=40