## Introduction to Buzz number

Buzz number is defined as a special form in a number series where either the number ends with 7 or is divisible by 7. This number is one of various other numbers that exist in the recreational number theory. This branch of mathematics where Buzz number exists is the one where the operations or logic that are developed are done for recreation. These numbers often act as food for the brain and are a part of the branch of pure mathematics, which deals with the integers and integer-valued functions. Some of the closely related numbers to the buzz number are prime numbers, meaning that the number is only divisible by 2 numbers in the entire number system, i.e., 1 and the number itself.

### The logic behind Buzz number

By now, we know that Buzz number is a part of recreational mathematics, and there is not a clear distinction of what comes under the genre of recreational mathematics. It is done more as a diversion from routine work or even playing games. These types of recreational mathematical numbers are a big part of mathematical puzzles, games, or even quizzes. The logic of a number being a buzz number might be asked in many technical interviews to test out the logic of implementation of mathematical operations that one might follow while coding. The logic(s) that are tested in finding a Buzz number is understanding if the developer is clear about the concept of modulo or remainder and how it can be used to find the last digit of a number. This operation is done in order to find if the last digit is a 7 or not. For example, when a number is divided by 10, the remainder that is generated is the last digit of the number. No one would need to check if that number is equal to 7 to see if the number ends with 7 or not. In case it gives a remainder as 7, we confirm that the number we passed is a buzz number.

The other logic that is tested is if the developer is aware of the division rules, i.e., if the developer knows the rule of divisibility. It means that if a number is divisible, the modulo should be equal to zero. Now, using the same logic, we see if the number, when divided by 7 yields zero as a remainder. Thus, if this logic is fulfilled alone, we say that a number is a buzz number. Also, as per the logic, if any of the rules i.e. divisibility by 7 or the last digit being 7 satisfies, it should return a positive value.

The last logic is to create an OR condition through which the above 2 checks are passed so that even if one of the conditions is true, we get a TRUE value returned. If both the conditions are true then as well a TRUE Boolean is returned.

### How to check Buzz’s number?

Understanding the logic behind the Buzz number is well understood in the previous section. Here we will put it into pseudocode to make the code generation in Java or C++, or python simplified.

- First, the number is taken as an input.
- Next, we create 2 flags, one to flag if the number ends with 7 and the other to flag if it is divisible by 7.
- Post the earlier step; we first use first check the modulo with 10 and check if the modulo is equal to 7. If yes, we use the flag which checks for numbers ending with 7 to be equal to 1 else 0.
- Next, we check the modulo with 7 and check if a value is equal to 0. If yes, we use the flag which checks for divisibility by 7 to be equal to 1 else 0.
- Then, use an OR statement to finally return the output of the above flags as a Boolean return type which gets checked in an if loop in the driver code to print the required statements in the console!

### Examples

Different examples are mentioned below:

#### Example #1

Finding Buzz number in C++

**Syntax**

`#include <cmath>`

#include <iostream>

using namespace std;

// Function to check Buzz number with Boolean return type

bool isBuzzNum(int num)

{

int flag_lastdig7, flag_divby7;

if (num % 10 == 7)

flag_lastdig7 = 1;

else

flag_lastdig7 = 0;

if (num % 7 == 0)

flag_divby7 = 1;

else

flag_divby7 = 0;

return ( flag_lastdig7==1 || flag_divby7 == 1);

}

int main(void)

{

int num;

char choice;

do{

cout << "Enter the number you want to check for being the buzz number\n";

cin >> num;

if (isBuzzNum(num))

cout << "Buzz Number\n";

else

cout << "Not a Buzz Number\n";

cout << "Do you want to continue to enter another number (y/n)...\n";

cin >> choice;

}while(choice=='y' || choice =='Y');

}

**Output:**

#### Example #2

Finding Buzz number in Python

**Syntax**

`def isBuzzNum(num) :`

if (num % 10 == 7):

flag_lastdig7 = 1

else:

flag_lastdig7 = 0

if (num % 7 == 0):

flag_divby7 = 1

else:

flag_divby7 = 0

return ( flag_lastdig7==1 or flag_divby7 == 1)

choice ='y'

while(choice=='y' or choice =='Y'):

print("Enter the number you want to check for being the buzz number")

num = int(input())

if (isBuzzNum(num)):

print("Buzz Number")

else:

print("Not a Buzz Number")

print("Do you want to continue to enter another number (y/n)...")

choice = input()

**Output:
**

#### Example #3

Finding Buzz number in Java

**Syntax**

`import java.util.*;`

public class Main {

static int flag_lastdig7, flag_divby7;

// Function to check Buzz number with Boolean return type

static boolean isBuzzNum(int num)

{

if (num % 10 == 7)

flag_lastdig7 = 1;

else

flag_lastdig7 = 0;

if (num % 7 == 0)

flag_divby7 = 1;

else

flag_divby7 = 0;

return ( flag_lastdig7==1 || flag_divby7 == 1);

}

// Main method

public static void main(String args[])

{

int n;

char choice;

Scanner sc= new Scanner(System.in);

do{

System.out.println("Enter the number you want to check for being the buzz number");

n= sc.nextInt();

if (isBuzzNum(n))

System.out.println("Buzz Number");

else

System.out.println("Not a Buzz Number");

System.out.println("Do you want to continue to enter another number (y/n)...");

choice= sc.next().charAt(0);

}while(choice=='y' || choice =='Y');

}

}

**Output:**

### Conclusion

In this article, we have looked at the logic and implementation of the Buzz number. However, one can easily find avenues to use the same code to make other applications that can be a part of any recreational mathematics, like puzzles or games!

### Recommended Articles

This is a guide to Buzz number. Here we discuss the logic and implementation of the Buzz number along with the examples and outputs. You may also have a look at the following articles to learn more –

11 Online Courses | 2 Hands-on Projects | 65+ Hours | Verifiable Certificate of Completion

4.5

View Course

Related Courses