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

C++Server Side ProgrammingProgramming

Given with a number ‘n’ and the task is to determine whether the given positive integer is a buzz number or not and display the result as an output.

What is Buzz Number?

For being a buzz number there are two conditions either of which must be true −

  • Number should end with digit 7 e.g. 27, 657, etc.

  • Number should be divisible by 7 e.g 63, 49, etc.

Input

number: 49

Output

it’s a buzz number

Explanation − since the number is divisible by 7 so it’s a buzz number

Input

number: 29

Output

it’s not a buzz number

Explanation − since the number is neither divisible by 7 nor end with digit 7 so it’s not a buzz number

Approach used in the given program is as follows

  • Input the number to check for the condition

  • Check whether the number is ending with digit 7 or divisible by 7

  • If the condition holds true print its a buzz number

  • If the condition doesn’t holds true print its not a buzz number

Algorithm

Start
Step 1→ declare function to check if a number is a buzz number of not
   bool isBuzz(int num)
      return (num % 10 == 7 || num % 7 == 0)
Step 2→ In main()
   Declare int num = 67
   IF (isBuzz(num))
      Print "its a buzz Number\n"
   End
   Else
      Print "its not a buzz Number\n"
   End
Stop

Example

 Live Demo

#include <cmath>
#include <iostream>
using namespace std;
// function to check if its a buzz number
bool isBuzz(int num){
   return (num % 10 == 7 || num % 7 == 0);
}
int main(){
   int num = 67;
   if (isBuzz(num))
      cout << "its a buzz Number\n";
   else
      cout << "its not a buzz Number\n";
}

Output

If run the above code it will generate the following output −

its a buzz Number
raja
Published on 13-Aug-2020 07:07:15
Advertisements