1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Russian乗算のプログラム

1
Posted at
russian.c
# 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;
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?