Skip to content

Instantly share code, notes, and snippets.

@Experiment5X
Created July 21, 2013 04:41
Show Gist options
  • Save Experiment5X/6047502 to your computer and use it in GitHub Desktop.
Save Experiment5X/6047502 to your computer and use it in GitHub Desktop.
Multiplying without the use of the * operator.
#include <stdio.h>
int mul(int a, int b)
{
if (b == 1)
return a;
else if (b == 0)
return 0;
return (a << 1) + mul(a, b - 2);
}
int main()
{
int a, b;
scanf("%d%d", &a, &b);
printf("%i\n", mul(a, b));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment