我是 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/