Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1567910
  • 博文数量: 354
  • 博客积分: 8137
  • 博客等级: 中将
  • 技术积分: 5137
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-26 15:40
文章分类

全部博文(354)

文章存档

2010年(300)

2009年(54)

分类: C/C++

2010-06-20 05:42:19

//求两数之间的最小公倍数和最大公约数

#include <stdio.h>

int main(int argc, char *argv[])
{
    int x, y, num1, num2, temp;
    printf("请输入两个正整数:\n");
    scanf("%d %d", &num1, &num2);
    if(num1 > num2)
    {
        temp = num1;
        num1 = num2;
        num2 = temp;
    }

    x = num1;
    y = num2;

    while(y != 0)
    {
        temp = x%y;
        x = y;
        y = temp;
    }

    printf("它们的最大公约数为: %d\n", x);
    printf("它们的最小公倍数为: %d\n",num1*num2/x);

    while(1);
    return 0;
}


阅读(846) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~