易截截图软件、单文件、免安装、纯绿色、仅160KB

C_使用while语句求两整数的最小公倍数与最大公约数

 源码:
# include <stdio.h>
 
int main()
{
    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);
    return 0;
}


相关文档:

C_普通位运算

 源码:
# include <stdio.h>
 
int main()
{
    /* 定义了一个无符号字符型变量,此变量只能用来存储无符号数 */
    unsigned char result;
    
    int a, b, c, d;
    a = 2;
    b = 4; ......

C_判断语句if的一般使用

源码:
# include <stdio.h>
     
int main()
{
        int x, y, z, mid, dec;
        printf("请任意输入三个整数:\n");
        scanf("%d %d %d", &x, & ......

C_使用switch语句

 源码:
# include <stdio.h>
 
int main()
{
    int num;
    /* 下面定义的各变量,分别代表个位,十位,百位,千位,万位,十万位以及位数 */
    int indiv, ten, hundred, thousand; 
    int ten_thousand, hundred_thous ......

C_使用for循环画菱形

 源码:
# include <stdio.h>
 
int main()
{
    int i, j, k;
     
    /* 变量i从0到4,表示所画菱形图的第一至第五行 */
    for(i = 0; i <= 4; i++)
    {
        /* ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号