Created
March 3, 2013 05:03
-
-
Save taishi41228/5074598 to your computer and use it in GitHub Desktop.
Russian乗算のプログラム ref: http://qiita.com/items/8317785118b1f8091818
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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