Program to check whether the given number is Buzz Number or not - GeeksforGeeks

31 Jan, 2022
A number is said to be Buzz Number if it ends with 7 OR is divisible by 7. The task is to check whether the given number is buzz number or not.Examples:  
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++
Java
Python3
PHP
C#
Javascript
// C++ program to check whether the// given number is Buzz Number or not.#include <cmath>#include <iostream>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 methodint 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 program to check whether the// given number is Buzz number or notimport 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.
# 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 methodi = 67j = 19if (isBuzz(i)) :    print ("Buzz Number")else :    print ("Not a Buzz Number")if (isBuzz(j)) :    print ("Buzz Number")else :    print ("Not a Buzz Number")   
<?php// PHP code to check Buzz Number // Function for Buzz Numberfunction isBuzz($num){    // checking if the number    // ends with 7 and is divisible by 7    return($num % 10 == 7 || $num % 7 == 0);   } // Driver Code$i = 67;$j = 43; if(isBuzz($i))print("Buzz Number\n");elseprint("Not Buzz Number\n");     if(isBuzz($j))print("Buzz Number\n");elseprint("Not Buzz Number\n"); // This code is contributed by akash7981?>
// C# program to check whether the// given number is Buzz number or notusing 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.
<script> // javascript program to check whether the// given number is Buzz number or not // function to check BUzz number.function isBuzz(num){    // checking if the number    // ends with 7 and is divisible by 7    return (num % 10 == 7 || num % 7 == 0);} // Driver methodvar i = 67, j = 19;if (isBuzz(i))    document.write("Buzz Number<br>");else    document.write("Not a Buzz Number<br>");if (isBuzz(j))    document.write("Buzz Number<br>");else    document.write("Not a Buzz Number<br>"); // This code is contributed by Princi Singh</script>
Output:  
Buzz Number
Not a Buzz Number
Time complexity : O(1) as there are atomic statements and no loops.
Auxiliary Space: O(1)This article is contributed by Nikita Tiwari. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. 
nitin mittal
princi singh
subhammahato348
amartyaghoshgfg
School Programming
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Constructors in Java
Exceptions in Java
Data Types
Inline Functions in C++
Pure Virtual Functions and Abstract Classes in C++
Difference between Abstract Class and Interface in Java
Destructors in C++
Python Exception Handling
Exception Handling in C++
Input and Output