The practice of seeking greatest common divisor, least common multiple and decomposition factorization of exotic flowers (C language)

Source: Internet
Author: User
Tags greatest common divisor integer numbers

The practice of seeking greatest common divisor, least common multiple and decomposition factorization of exotic flowers (C language)

1 /*2 The most wonderful seeking greatest common divisor and least common multiple3 Create by Laog4 Time July 27, 2017 12:23:145 */6 7 //two numbers of greatest common divisor8 //Two numbers of least common multiple9 //decomposes a positive integer factorization--and 2.3.5Ten  One#include <stdio.h> A  - intmain1 () - { the     //3,4 -     // - -     intv; -scanf"%d", v); +     intA = -; -     intStart =1; +     intEnd =A; A     intresult =0; at      for(i = start; I <= end; i++) -     { -         //find the largest prime number in a -         if(a% i = =0&& I%2!=0) -         { -result =i; in         } -     } to printf (result); + } - //the most wonderful to seek greatest common divisor and least common multiple the intmain2 () * { $     //Greatest Common DivisorPanax Notoginseng     //input -     intA = -; the     intb = -; +     //flags that declare loops A     intStart =1; the     intend = a < b?a:b; +     //declares the traversal of the receiving greatest common divisor -     intMaxgongyue =0; $      for(inti = start; I < end; i++) $     { -         if(a% i = =0&& b% i = =0) -         { theMaxgongyue =i; -         }Wuyi     } the printf (Maxgongyue); -     return 0; Wu } - //Beg least common multiple About intmain3 () $ { -     //least common multiple -     //input -     intA = -; A     intb = -; +     //declaring loop Flags the     intStart = A *b; -     intend = a > B?a:b; $     //declaring a variable that receives least common multiple the     intMingongbei =0; the      for(inti = start; I >= end; i--) the     { the         if(i% A = =0&& I% b = =0) -         { inMingongbei =i; the         } the     } About printf (mingongbei); the     return 0; the } the  + //determine if a number is prime - intPanduanzhishu (ints) the {Bayi     intSign =1; the      for(inti =2; I <= process-1; i++) the     { -         if(s% i = =0) -         { theSign =0; the         } the     } the     returnSign ; - } the  the intmain4 () the {94     //Decomposition factorization the     //input the     intA = -; the     intStart1 =1;98     intEnd1 =A; About     intProcess =A; -      while(1)101     {102          for(inti = Start1; I < end; i++)103         {104             if(Panduanzhishu (i)) the             {106                 if(process% i = =0)107                 {108 printf (i);109Process = Process/i; the                      Break;111                 } the             }113         } the         //when the Process=1 time to jump out of the loop the         if(Process = =1) the         {117              Break;118         }119     } - }121 /**122 The following approach is more normal123 using Algorithms124 */ the /*126 There are two integers a and B:127  - ①a%b remainder C129  the ② If c=0, then B is a two-digit greatest common divisor131  the ③ If c≠0, then a=b,b=c, then go back to execute ①133 134 For example, the greatest common divisor process for 27 and 15 is:135 136 27÷15 Yu 1215÷12 312÷3 0 So, 3 is the greatest common divisor137 */138 voidMain ()/*seeking greatest common divisor by the method of dividing*/   139 {    $    intm, N, a, B, t, C; 141printf"Input, Integer numbers:\n"); 142scanf"%d%d", &a, &b); 143M=a; n=b; 144     while(b!=0)/*The remainder is not 0 and continues to divide until the remainder is 0*/   145{c=a%b; a=b; b=C;} 146printf"The largest common divisor:%d\n", a); 147printf"The least common multiple:%d\n", m*n/a); 148 }149   

The practice of seeking greatest common divisor, least common multiple and decomposition factorization of exotic flowers (C language)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.