objective-c - 最大公约数 Objective-C

标签 objective-c greatest-common-divisor

我是 ios 编程的新手。我对 GCD 计划有疑问。

01 // This program finds the greatest common divisor of two nonnegative integer values
02 
03 #import <Foundation/Foundation.h>
04 
05 int main (int argc, const char * argv[]) {
06     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
07     unsigned int u, v, temp;
08     
09     NSLog(@"Please type in two nonnegative integers.");
10     scanf("%u%u", &u, &v);
11     
12     while (v != 0) {
13         temp = u % v;
14         u = v;
15         v = temp;
16     }
17     
18     NSLog(@"Their greatest common divisor is %u", u);
19     
20     [pool drain];
21     return 0;
22 }

我不明白这部分:
while(v!=0)
     temp = u%v
     u =v;
     v = temp;

那是什么意思,用英语怎么说?

最佳答案

% 是 mod operator .这三行划分 u来自 v并将剩余部分存储在 temp 中。然后u获取 v 的值, 和 v得到余数。重复该过程,同时 v不是 0。

关于objective-c - 最大公约数 Objective-C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7863988/

相关文章:

ios - 如何在 iOS 中的 TableView 中实现下拉菜单

python - 在递归中使用 return 的地方

使用 GUI 界面的 Java 最大公约数 - Int/String/Calculations 的问题

c - 比较素检查?

C++程序计算最大公约数

ios - 对于 Soap NSURLConnection,请确保您的应用支持 IPv6 网络,因为需要 IPv6 兼容性

ios - NSString componentsSeparatedByCharactersInSet:如何分隔带标点符号?

objective-c - 如何在 Xcode 中添加 Watch 或 Inspect?

ios - iOS9.1 的UITouchType

c - GCD逻辑错误