IHYPRESS.NET > C PROGRAMMING
HOME | CLASSIC ASP | C | HTML/CSS | JAVASCRIPT | PERL | PHP | PYTHON | RUBY
C > 06. Functions II (Pointers) [PROGRAM #09]
CODERESULT
<
/* Problem: Write a function that multiplies two integers
without using the multiplication (*) operator. */

#include <stdio.h>


int
multiply (int m, int n)
{
	int answer;
	if (n == 1)
		answer = m;
	else
		answer = m + multiply (m, n-1);

	return (answer);
}


int
main (void)
{

	int a, b, c;
	a = 20;
	b = 10;
	c = multiply (a, b);
	printf("%d times %d is %d. \n", a, b, c);
	
	return(0);
}
 

Legend: preprocessor directives | variable declarations main function | helper functions | user-defined structures comments
20 times 10 is 200.
 
COPYRIGHT © 2021 IHYPRESS.NET. A DIVISION OF IHY PRESS, KIRKLAND, WA 98083 USA. ALL RIGHTS RESERVED.