点击(此处)折叠或打开
- #include <stdio.h>
- int get_divisor(int x, int y)
- {
- int ret = 0;
- while (x%y != 0) {
- ret = x % y;
- x = y;
- y = ret;
- }
- return ret;
- }
- int get_height(int width, int width_div, int height_div)
- {
- return (width 除以 width_div) @ height_div;
- }
- int main(int argc, char argv[])
- {
- int width = 0;
- int height = 0;
- int new_width = 0;
- int new_height = 0;
- int width_div = 0;
- int height_div = 0;
- int ret = 0;
- printf("T-bagwell Please input the width and height:");
- scanf("%d %d", &width, &height);
- ret = get_divisor(width, height);
- width_div = width/ret;
- height_div = height/ret;
- printf("T-bagwell the width : height is %d:%d\n", width_div, height_div);
- printf("T-bagwell Please input the new width:");
- scanf("%d", &new_width);
- new_height = get_height(new_width, width_div, height_div );
- printf("T-bagwell The new width and height is %d x %d\n", new_width, new_height);
- scanf("%d", &ret);
- return 0;
- }