使用 C++ 程式檢查數量是否具有盧比面值或不具有盧比面值
假設我們有兩個數字 K 和 X。考慮 Amal 擁有 K 張 500 盧比的紙幣。我們必須檢查這些紙幣是否總計 X 盧比。
因此,如果輸入為 K = 2;X = 900,則輸出將為 True,因為 2*500 = 1000,且不小於 900。
步驟
要解決此問題,我們將按照以下步驟進行 −
if (500 * k) >= x, then: return true Otherwise return false
範例
讓我們看看以下實現,以獲得更好的理解 −
#include <bits/stdc++.h>
using namespace std;
bool solve(int k, int x){
if ((500 * k) >= x){
return true;
} else{
return false;
}
}
int main(){
int K = 2;
int X = 900;
cout << solve(K, X) << endl;
}輸入
2, 900
輸出
1
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP