該數字是否為 29 的倍數
這是一個簡單的問題。我們可以使用模運算子 (%) 來檢查給定的數字是否為 29 的倍數。讓我們看幾個示例。
輸入
29 254
輸出
1 0
演算法
實現
以下是上述演算法在 C++ 語言中的實現
#include <bits/stdc++.h>
using namespace std;
bool isDivisibleBy29(long long n) {
return n % 29 == 0;
}
int main() {
cout << isDivisibleBy29(29) << endl;
cout << isDivisibleBy29(234567876543) << endl;
cout << isDivisibleBy29(234567657329) << endl;
return 0;
}輸出
如果你執行以上程式碼,你將獲得以下結果。
1 1 0
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java 語言
iOS
HTML
CSS
Android 系統
Python 語言
C 程式設計
C++ 語言
C#
MongoDB
MySQL
Javascript 語言
PHP 語言