雞兔同籠代碼?
//有雉兔同籠,上有三十五頭,下有九十四足,問雉兔各幾何?
int rabbit = 0; //兔子數量
int hen = 0; //雞數量
for (int i = 1 ; i < 35 ; i++ ) {
for (int j = 1 ; j < 35 ; j++ ) {
rabbit = i;
hen = j;
if (rabbit + hen == 35 && rabbit * 4 + hen * 2 == 94) {
NSLog(@"rabbit = %d , hen = %d",rabbit,hen); //rabbit = 12 , hen = 23
}
}
}
上一篇ff的補碼是多少