创建一个程序,告诉用户一个数字是否可被5整除

时间:2016-03-07 07:39:31

标签: c++

我正在尝试创建一个程序,该程序执行标题所说的内容,可以被5整除,仅表示整数值。到目前为止这里是代码,虽然它不完整: -

#include <iostream>
using namespace std;

int main()

{

    int x;
    cout << "Enter a number to see if its divisable by 5" << endl;
    cin >> x;
    x = x / 5;
    if (x ==)
    {
        cout << "yes it is divisible by 5 and the value is" << x << endl;
    }
    else
    {
        cout << "no its not divisable by 5" << endl;
    }

    return 0;
}

我对if语句的内容感到困惑,以便它识别分配给x的数字是否可以被5整除。有人可以帮帮我吗?

2 个答案:

答案 0 :(得分:5)

你想要这个(改为使用modulo%运算符)

    Dim Arr() As Variant ' declare an unallocated array.
Arr = Range("I:I") ' Arr is now an allocated array
Set dict = CreateObject("Scripting.Dictionary")
Dim iRow As Integer
iRow = 1
 Dim parms As Variant
   Dim rg As Range
    For Each rg In Sheet1.Range("I:I")
        ' Print address of cells that are negative
        'MsgBox (rg.Value)
         'result = result & rg.Value
          dict.Add rg.Value
          iRow = (iRow + 1)        
    Next
MsgBox (dict.Item(1))
Set dict = Nothing
'WebBrowser1.Navigate2 "http://localhost/excelmaps/maps.php?adr=" & parms
End Sub

答案 1 :(得分:1)

%

中使用模/代替x = x / 5;

modulo提醒25%5 = 0,其中25/5 = 5

if (x ==)语句中添加x==0