In: Computer Science
Write a function that accepts two arguments (say a and b) by value and one argument (say c) by reference. Then it calculates the multiplication of all the numbers between a and b (inclusive) and saves the results in c. The function does not return any value.
Code:
#include <stdio.h>
//declare function
void multiply(int a,int b,int* c);
int main(void) {
  int a,b,c;
  a = 1;
  b = 4;
  //call function  with a, b and reference of c
  multiply(a,b,&c);
  //check that multiplication of a to b will saves in c or not
  printf("Multiplication of %d to %d(inclusive) numbers is c = %d",a,b,c );
  return 0;
}
void multiply(int a,int b,int* c){
  int i,mul=1;
  //it will start with a and iterate till b and
  //each number multiply by mul variable
  for(i = a;i<=b;i++)
    mul = mul * i;
  //it saves multiplication to refrence of c variable
  *c = mul;
}
Output:
.
