Given an integer N, subtract the first digit of the number N from it i. e if n is 245 then subtract 2 from it making it 245-2 = 243. Keep on doing this operation until the number becomes 0.
Your task is to calculate the number of operation required to make this number N zero
Answers
Answer:
In this case I am using C++ language here. Not sure if I am right or not... So here is my answer.
Explanation:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number: ";
cin >> n;
cout << "The number of turns it took is " << n / 2 << endl;
return 0;
}
Concept:-
An expression set up of a subject, action word, item, and modifiers. A gathering of modifiers, a subject, an action word, and an item. A sentence that is developed with a subject, action word, item, and modifiers. a blend of subjects, action words, items, and modifiers.
Given:-
Given that an integer , subtract the first digit of the number from it i. e if is then subtract from it making it . Keep on doing this operation until the number becomes .
Find:-
We need to find the number of operation required to make this number zero.
Solution:-
program to find the count of Steps to
reduce to zero by subtracting its most
significant digit at every step
#include
using namespace std;
Function to count the number
of digits in a number m
int countdig(int m)
if
return ;
else
return ;
Function to count the number of
steps to reach
int countSteps(int x)
count the total number of steps
int ;
int last ;
iterate till we reach
while (last)
count the digits in last
int digits countdig(last);
decrease it by
digits ;
find the number on whose division,
we get the first digit
int divisor , digits;
first digit in last
int first lastdivisor;
find the first number less than
last where the first digit changes
int lastnumber first divisor;
find the number of numbers
with same first digit that are jumped
int skipped (last lastnumber) first;
skipped;
count the steps
skipped;
the next number with a different
first digit
last last (first skipped);
return ;
Driver code
int main
{
int ;
cout countSteps;
return ;
Hence, the operation can be done with to be zero.
#SPJ2