Program to check whether the given number is Buzz Number or not
Last Updated :
16 Feb, 2023
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++
#include <cmath>
#include <iostream>
using namespace std;
bool isBuzz( int num)
{
return (num % 10 == 7 || num % 7 == 0);
}
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
import java.io.*;
import java.util.*;
class GFG {
static boolean isBuzz( int num)
{
return (num % 10 == 7 || num % 7 == 0 );
}
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" );
}
}
|
Python3
def isBuzz(num) :
return (num % 10 = = 7 or num % 7 = = 0 )
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
<?php
function isBuzz( $num )
{
return ( $num % 10 == 7 || $num % 7 == 0);
}
$i = 67;
$j = 43;
if (isBuzz( $i ))
print ( "Buzz Number\n" );
else
print ( "Not Buzz Number\n" );
if (isBuzz( $j ))
print ( "Buzz Number\n" );
else
print ( "Not Buzz Number\n" );
?>
|
C#
using System;
class GFG {
static bool isBuzz( int num)
{
return (num % 10 == 7 || num % 7 == 0);
}
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" );
}
}
|
Javascript
<script>
function isBuzz(num)
{
return (num % 10 == 7 || num % 7 == 0);
}
var 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>" );
</script>
|
Output:
Buzz Number
Not a Buzz Number
Time complexity : O(1) as there are atomic statements and no loops.
Auxiliary Space: O(1)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...