Computer Science, asked by aradhyasingh4438, 4 months ago


Create a program to check if a number is a Buzz number or not. (Buzz number is a number that ends with
7 or is divisible by 7).

Answers

Answered by sattus222
2

Answer:

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

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.

Recommended: Please try your approach on {IDE} first, before moving on to the solution.

// 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 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";

}

Output:

Buzz Number

Not a Buzz Number

Time complexity : O(1) as there are atomic statements and no loops.

Answered by TheUntrustworthy
2

import java. util. *

class Buzz

{

public static void main (string args[])

{

Scanner sc= new Scanner (System. in);

int x;

System.out.println ("Enter a number");

x=sc. nextInt ();

if(x%==0||x/10==7)

System.out.println (x+"is Buzz number");

else

System.out.println (x+"is not Buzz");

}

}

Similar questions