
- 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
Convert to number with digits as 3 and 8 only in C++
In this tutorial, we will be discussing a program to convert a number to have digits as 3 and 8 only.
For this we will be provided with a random number. Our task is to convert its digits to be only 3 and 8 by either adding/subtracting 1 from the number or converting digits of the number to any desired digit.
Example
#include <bits/stdc++.h> using namespace std; //calculating minimum operations required int cal_min(long long int num){ //calculating remainder and operations int rem; int count = 0; while (num) { rem = num % 10; if (!(rem == 3 || rem == 8)) count++; num /= 10; } return count; } int main(){ long long int num = 2341974; cout << "Minimum Operations: " << cal_min(num); return 0; }
Output
Minimum Operations: 6
- Related Articles
- Minimum number with digits as and 7 only and given sum in C++
- Finding n-th number made of prime digits (2, 3, 5 and 7) only in C++
- Find n’th number in a number system with only 3 and 4 in C++
- Convert number to reversed array of digits JavaScript
- Convert number to a reversed array of digits in JavaScript
- Find smallest number with given number of digits and sum of digits in C++
- How to Convert the Phone Number Format to Digits in Excel?
- Find the Largest number with given number of digits and sum of digits in C++
- How to find the 3 Pythagorean triplets with only one number?
- Check if the given decimal number has 0 and 1 digits only in Python
- Adding one to number represented as array of digits in C++?
- Program to find multiple of n with only two digits in Python
- 8085 program to find sum of digits of 8 bit number
- 8086 program to find sum of digits of 8 bit number
- n-th number with digits in {0, 1, 2, 3, 4, 5} in C++

Advertisements