Computer Science, asked by jaeguri, 8 months ago

Write a program to accept a number and using ternary operator, check whether it is a buzz number or not. A

buzz number either ends with 7 or is divisible by 7. For example: numbers like 49, 47, 63,427 are buzz

numbers. But numbers like 100, 25 and 62 are not​

Answers

Answered by manthansarkar1983
2

Explanation:

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 Brenquoler
6

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

}

}

A Buzz number is a number which is divisible by 7 or whose last digit is 7.

Similar questions