
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Program to check whether the given number is Buzz Number or not in C++
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
#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
- Related Articles
- Program to check whether given number is Narcissistic number or not in Python
- Check whether the given number is Euclid Number or not in Python
- Write a Golang program to check whether a given number is prime number or not
- Check whether a given number is Polydivisible or Not
- 8085 program to check whether the given 16 bit number is palindrome or not
- Program to check whether a number is Proth number or not in C++
- C# Program to Check Whether the Entered Number is an Armstrong Number or Not
- Check whether the given number is Wagstaff prime or not in Python
- Swift Program to Check if the given number is Perfect number or not
- C++ Program to Check Whether a Number is Prime or Not
- C++ Program to Check Whether a Number is Palindrome or Not
- C Program to Check Whether a Number is Prime or not?
- Java Program to Check Whether a Number is Prime or Not
- Write a Golang program to check whether a given number is a palindrome or not
- 8085 program to check whether the given number is even or odd
