📜  检查给定号码是否为 Buzz Number 的程序

📅  最后修改于: 2022-05-13 01:57:59.559000             🧑  作者: Mango

检查给定号码是否为 Buzz Number 的程序

如果一个数字以 7 结尾或能被 7 整除,则称该数字为 Buzz Number。
任务是检查给定的数字是否是嗡嗡声。
例子:

Input : 63
Output : Buzz Number
Explanation: 63 is divisible by 7, one
of the condition is satisfied.

Input : 72
Output : Not a Buzz Number
Explanation: 72 % 7 != 0, 72 is neither 
divisible by 7 nor it ends with 7 so 
it is not a Buzz Number.

C++
// C++ program to check whether the
// given number is Buzz Number or not.
#include 
#include 
using namespace std;
 
// function to check BUzz number.
bool isBuzz(int num)
{
    // checking if the number
    // ends with 7 and is divisible by 7
    return (num % 10 == 7 || num % 7 == 0);
}
 
// Driver method
int main(void)
{
    int i = 67, j = 19;
    if (isBuzz(i))
        cout << "Buzz Number\n";
    else
        cout << "Not a Buzz Number\n";
    if (isBuzz(j))
        cout << "Buzz Number\n";
    else
        cout << "Not a Buzz Number\n";
}


Java
// Java program to check whether the
// given number is Buzz number or not
import java.io.*;
import java.util.*;
class GFG {
 
    // function to check BUzz number.
    static boolean isBuzz(int num)
    {
        // checking if the number
        // ends with 7 and is divisible by 7
        return (num % 10 == 7 || num % 7 == 0);
    }
 
    // Driver method
    public static void main(String args[])
    {
        int i = 67, j = 19;
        if (isBuzz(i))
            System.out.println("Buzz Number");
        else
            System.out.println("Not a Buzz Number");
        if (isBuzz(j))
            System.out.println("Buzz Number");
        else
            System.out.println("Not a Buzz Number");
    }
}
// This code is contributed by Nikita Tiwari.


Python3
# Python program to check whether the
# given number is Buzz Number or not.
 
# function to check BUzz number.
def isBuzz(num) :
     
    # checking if the number
    # ends with 7 and is divisible by 7
    return (num % 10 == 7 or num % 7 == 0)
 
# Driver method
i = 67
j = 19
if (isBuzz(i)) :
    print ("Buzz Number")
else :
    print ("Not a Buzz Number")
if (isBuzz(j)) :
    print ("Buzz Number")
else :
    print ("Not a Buzz Number")


PHP


C#
// C# program to check whether the
// given number is Buzz number or not
using System;
 
class GFG {
 
    // function to check BUzz number.
    static bool isBuzz(int num)
    {
         
        // checking if the number
        // ends with 7 and is
        // divisible by 7
        return (num % 10 == 7 || num % 7 == 0);
    }
 
    // Driver method
    public static void Main()
    {
        int i = 67, j = 19;
         
        if (isBuzz(i))
            Console.WriteLine("Buzz Number");
        else
            Console.Write("Not a Buzz Number");
             
        if (isBuzz(j))
            Console.Write("Buzz Number");
        else
            Console.Write("Not a Buzz Number");
    }
}
 
// This code is contributed by Nitin mittal.


Javascript


输出:

Buzz Number
Not a Buzz Number

时间复杂度:O(1),因为有原子语句,没有循环。