In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to find the maximum common divisor in C language. the article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Case solving
If you need to ask for the greatest common divisor of two positive integers, using the Euclidean algorithm, it goes like this:
1997 / 615 = 3 (remaining 152)
615 / 152 = 4 (remaining 7)
152 / 7 = 21 (remaining 5)
7 / 5 = 1 (remaining 2)
5 / 2 = 2 (remaining 1)
2 / 1 = 2 (remainder 0)
So far, the maximum common divisor is 1.
The division operation is done repeatedly with the divisor and the remainder. When the remainder is 0, the divisor of the current formula is taken as the maximum common divisor, so the maximum common divisor of 1997 and 615 is obtained.
Novice version
# include # include int result (int m, int n) {int r; if (m > n) {r = m, m = n, n = r;} r = n% m; while (r! = 0) {n = m; m = r; r = n% m;} return m;} int main () {
Printf ("result:%d\ n", result (12,9)); return 0;}
This way of writing is a very simple idea.
1. First find the maximum of the two.
two。 Then use a loop to describe tossing and turning and divide.
Big shot version
# include
# include int result (int m, int n) {return n? Result (n, m% n): n;} int main () {printf ("result:%d\ n", result (12, 9)); return 0;} this is how to find the maximum common divisor in the C language shared by the editor. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.