zoukankan      html  css  js  c++  java
  • 求两个数的最大公约数

    /*1. 给定两个整形变量的值,将两个值的内容进行交换。
    2. 不允许创建临时变量,交换两个数的内容(附加题)
    3.求10 个整数中最大值。
    4.将三个数按从大到小输出。

    5.求两个数的最大公约数。*/

    下面我们定义函数在main函数里面调用实现
    #define _CRT_SECURE_NO_WARNINGS 1
    #include<stdio.h>
    #include<stdlib.h>
    int greatest(int a, int b){
      if (b != 0)
        return greatest(b, a%b);
      else
        return a;
    }
    void dzx(int a, int b, int c){
      if (a > b){
        if (c>a)
          printf("%d %d %d ", c, a, b);
        else if (c>b)
          printf("%d %d %d ", a, c, b);
        else
          printf("%d %d %d ", a, b, c);
      }
      else{
        if (c>b)
          printf("%d %d %d ", c, b, a);
        else if (c>a)
          printf("%d %d %d ", b, c, a);
        else
          printf("%d %d %d ", b, a, c);
      }
    }
    int maxInt(int arr[]){
      int max = 0;
      for (int i = 0; i < 10; i++){
        if (max < arr[i])
          max = arr[i];
       }
      return max;
    }
    void swap1(int a, int b){
      int temp = a;
      a = b;
      b = temp;
      printf("a = %d, b = %d ", a, b);
    }
    void swap2(int a, int b){
      a = a+b;
      b = a - b;
      a = a - b;
      printf("a = %d, b = %d ", a, b);
    }
    void swap3(int a, int b){
      a = a^b;
      b = a^b;
      a = a^b;
      printf("a = %d, b = %d ", a, b);
    }
    int main(){
      int a = 0;
      int b = 0;
      scanf("%d %d", &a, &b);
      swap1(a, b);
      swap2(a, b);
      swap3(a, b);

      int arr[10];
      for (int i = 0; i < 10; i++){
        scanf("%d", &arr[i]);
      }
      int max = maxInt(arr);
      printf("max = %d ",max);


      int c = 0;
      int d = 0;
      int e = 0;
      scanf("%d %d %d", &c, &d, &e);
      dzx(c,d,e);

      int f = 0;
      int g = 0;
      scanf("%d %d ", &f, &g);
      int zd = greatest(f, g);
      printf("zd = %d ",zd);

      system("pause");
      return 0;
    }

  • 相关阅读:
    selenium 8大元素定位方法
    selenium环境安装及简单使用
    Python json序列化和反序列化
    pytest使用allure生成测试报告
    Windows10下JDK15的安装教程
    Ansible:服务器巡检_3、Windows 平台巡检
    转载:shell中各种括号的作用详解()、(())、[]、[[]]、{}(推荐)
    Tips: Linux 中 当形参名称是 变量时,如何取出全部的实参
    Python 问题记录:XXX.whl is not a supported wheel on this platform.
    Ansible:服务器巡检_2、Linux 服务器巡检脚本
  • 原文地址:https://www.cnblogs.com/du001011/p/10010493.html
Copyright © 2011-2022 走看看