Skip to content

Instantly share code, notes, and snippets.

@taishi41228
Created March 3, 2013 05:03
Show Gist options
  • Save taishi41228/5074598 to your computer and use it in GitHub Desktop.
Save taishi41228/5074598 to your computer and use it in GitHub Desktop.
Russian乗算のプログラム ref: http://qiita.com/items/8317785118b1f8091818
#include <stdio.h>
int Russian (int x, int y){
int m;
if (x % 2 != 0) {
m = y;
} else {
m = 0;
}
while (x != 1) {
x = x / 2;
y = 2 * y;
if (x % 2 != 0) {
m = m + y;
}
}
return m;
}
int main(int argc, const char * argv[])
{
int a = 36, b = 17, result = Russian(a,b);
printf("%d × %d = %d\n",a, b, result);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment