Posted on by Kalkicode
Code Mathematics

# Check whether the given number is buzz number or not

The Buzz number problem involves determining whether a given number is a Buzz number or not. A Buzz number is a positive integer that meets a specific criterion involving its digits. To check whether a number is a Buzz number, we need to examine the last digit of the number and check if the number is divisible by 7 or if the last digit is 7.

## Problem Statement

A Buzz number is a positive integer where at least one of the following conditions holds:

1. The number is divisible by 7.
2. The last digit of the number is 7.

## Example

Let's take the number 126 as an example to illustrate whether it's a Buzz number or not.

• 126 is not divisible by 7.
• The last digit of 126 is not 7.

Since none of the conditions are satisfied, 126 is not a Buzz number.

## Idea to Solve

To solve this problem, we only need to implement a function called `isBuzzNo` that takes a number as input and checks whether it's a Buzz number or not based on the conditions mentioned. We don't need a separate function to check for prime numbers, as was the case in the Moran number problem.

## Standard Pseudocode

``````function isBuzzNo(number)
if number is divisible by 7 or last digit of number is 7
return true
else
return false``````

## Algorithm with Explanation

1. Implement the `isBuzzNo` function as described in the pseudocode. It checks whether the number is divisible by 7 or if the last digit of the number is 7.
2. In the main function, call `isBuzzNo` for each test case (numbers 126, 123, 2120, 107, and 170). Print whether each number is a Buzz number or not based on the returned value from `isBuzzNo`.

## Program Solution

``````// C program for
// Check whether the given number is buzz number or not
#include <stdio.h>

void isBuzzNo(int number)
{
if (number % 7 == 0 || number % 10 == 7)
{
// When last digit is 7
// or number is divisible by 7
printf(" Number %d is buzz number\n", number);
}
else
{
printf(" Number %d is not buzz number\n", number);
}
}
int main(int argc, char
const *argv[])
{
// Test Cases
isBuzzNo(126);
isBuzzNo(123);
isBuzzNo(2120);
isBuzzNo(107);
isBuzzNo(170);
return 0;
}``````

#### input

`````` Number 126 is buzz number
Number 123 is not buzz number
Number 2120 is not buzz number
Number 107 is buzz number
Number 170 is not buzz number``````
``````/*
Java Program for
Check whether the given number is buzz number or not
*/
public class BuzzNumber
{
public void isBuzzNo(int number)
{
if (number % 7 == 0 || number % 10 == 7)
{
// When last digit is 7
// or number is divisible by 7
System.out.println(" Number " + number + " is buzz number");
}
else
{
System.out.println(" Number " + number + " is not buzz number");
}
}
public static void main(String[] args)
{
// Test Cases
}
}``````

#### input

`````` Number 126 is buzz number
Number 123 is not buzz number
Number 2120 is not buzz number
Number 107 is buzz number
Number 170 is not buzz number``````
``````// Include header file
#include <iostream>

using namespace std;
/*
C++ Program for
Check whether the given number is buzz number or not
*/
class BuzzNumber
{
public: void isBuzzNo(int number)
{
if (number % 7 == 0 || number % 10 == 7)
{
// When last digit is 7
// or number is divisible by 7
cout << " Number " << number << " is buzz number" << endl;
}
else
{
cout << " Number " << number << " is not buzz number" << endl;
}
}
};
int main()
{
// Test Cases
return 0;
}``````

#### input

`````` Number 126 is buzz number
Number 123 is not buzz number
Number 2120 is not buzz number
Number 107 is buzz number
Number 170 is not buzz number``````
``````// Include namespace system
using System;
/*
Csharp Program for
Check whether the given number is buzz number or not
*/
public class BuzzNumber
{
public void isBuzzNo(int number)
{
if (number % 7 == 0 || number % 10 == 7)
{
// When last digit is 7
// or number is divisible by 7
Console.WriteLine(" Number " + number + " is buzz number");
}
else
{
Console.WriteLine(" Number " + number + " is not buzz number");
}
}
public static void Main(String[] args)
{
// Test Cases
}
}``````

#### input

`````` Number 126 is buzz number
Number 123 is not buzz number
Number 2120 is not buzz number
Number 107 is buzz number
Number 170 is not buzz number``````
``````<?php
/*
Php Program for
Check whether the given number is buzz number or not
*/
class BuzzNumber
{
public	function isBuzzNo(\$number)
{
if (\$number % 7 == 0 || \$number % 10 == 7)
{
// When last digit is 7
// or number is divisible by 7
echo " Number ".\$number.
" is buzz number".
"\n";
}
else
{
echo " Number ".\$number.
" is not buzz number".
"\n";
}
}
}

function main()
{
// Test Cases
}
main();``````

#### input

`````` Number 126 is buzz number
Number 123 is not buzz number
Number 2120 is not buzz number
Number 107 is buzz number
Number 170 is not buzz number``````
``````/*
Node JS Program for
Check whether the given number is buzz number or not
*/
class BuzzNumber
{
isBuzzNo(number)
{
if (number % 7 == 0 || number % 10 == 7)
{
// When last digit is 7
// or number is divisible by 7
console.log(" Number " + number + " is buzz number");
}
else
{
console.log(" Number " + number + " is not buzz number");
}
}
}

function main()
{
// Test Cases
}
main();``````

#### input

`````` Number 126 is buzz number
Number 123 is not buzz number
Number 2120 is not buzz number
Number 107 is buzz number
Number 170 is not buzz number``````
``````#  Python 3 Program for
#  Check whether the given number is buzz number or not
class BuzzNumber :
def isBuzzNo(self, number) :
if (number % 7 == 0 or number % 10 == 7) :
#  When last digit is 7
#  or number is divisible by 7
print(" Number", number ,"is buzz number")
else :
print(" Number", number ,"is not buzz number")

def main() :
#  Test Cases

if __name__ == "__main__": main()``````

#### input

`````` Number 126 is buzz number
Number 123 is not buzz number
Number 2120 is not buzz number
Number 107 is buzz number
Number 170 is not buzz number``````
``````#  Ruby Program for
#  Check whether the given number is buzz number or not
class BuzzNumber
def isBuzzNo(number)
if (number % 7 == 0 || number % 10 == 7)
#  When last digit is 7
#  or number is divisible by 7
print(" Number ", number ," is buzz number", "\n")
else
print(" Number ", number ," is not buzz number", "\n")
end

end

end

def main()
#  Test Cases
end

main()``````

#### input

`````` Number 126 is buzz number
Number 123 is not buzz number
Number 2120 is not buzz number
Number 107 is buzz number
Number 170 is not buzz number
``````
``````/*
Scala Program for
Check whether the given number is buzz number or not
*/
class BuzzNumber()
{
def isBuzzNo(number: Int): Unit = {
if (number % 7 == 0 || number % 10 == 7)
{
// When last digit is 7
// or number is divisible by 7
println(" Number " + number + " is buzz number");
}
else
{
println(" Number " + number + " is not buzz number");
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: BuzzNumber = new BuzzNumber();
// Test Cases
}
}``````

#### input

`````` Number 126 is buzz number
Number 123 is not buzz number
Number 2120 is not buzz number
Number 107 is buzz number
Number 170 is not buzz number``````
``````/*
Swift 4 Program for
Check whether the given number is buzz number or not
*/
class BuzzNumber
{
func isBuzzNo(_ number: Int)
{
if (number % 7 == 0 || number % 10 == 7)
{
// When last digit is 7
// or number is divisible by 7
print(" Number", number ,"is buzz number");
}
else
{
print(" Number", number ,"is not buzz number");
}
}
}
func main()
{
// Test Cases
}
main();``````

#### input

`````` Number 126 is buzz number
Number 123 is not buzz number
Number 2120 is not buzz number
Number 107 is buzz number
Number 170 is not buzz number``````
``````/*
Kotlin Program for
Check whether the given number is buzz number or not
*/
class BuzzNumber
{
fun isBuzzNo(number: Int): Unit
{
if (number % 7 == 0 || number % 10 == 7)
{
// When last digit is 7
// or number is divisible by 7
println(" Number " + number + " is buzz number");
}
else
{
println(" Number " + number + " is not buzz number");
}
}
}
fun main(args: Array < String > ): Unit
{
// Test Cases
}``````

#### input

`````` Number 126 is buzz number
Number 123 is not buzz number
Number 2120 is not buzz number
Number 107 is buzz number
Number 170 is not buzz number``````

## Time Complexity

The time complexity of this code is O(1) for each test case since the checks involved are simple arithmetic operations and comparisons.

## Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

Categories
Relative Post