to remove the repeated numbers from the given .
i.e..,
if the input is 12233
output should of
123
Answer Posted / sujai cn
#include <iostream>
#include <math.h>
#include<conio.h>
using namespace std;
void main()
{
int num = 0;
int ReverseNumber(int num);
int RemoveDuplicateDigits(int num);
int ReverseOfInput = 0;
cout<<"Please enter the number\n";
cin >> num;
ReverseOfInput = ReverseNumber(num);
cout<<"The number after removing duplicate digits is "
<< ReverseNumber(RemoveDuplicateDigits(ReverseOfInput)) ;
getch();
}
int ReverseNumber(int num)
{
int revnum = num;
int nodigits = 0;
int rem = 0;
while(revnum > 0)
{
nodigits ++;
revnum = revnum / 10;
}
revnum = 0;
nodigits --;
while(num > 0)
{
rem = num % 10 ;
revnum = revnum + rem * (int) (pow (10 ,nodigits));
nodigits --;
num = num / 10;
}
return revnum;
}
int RemoveDuplicateDigits(int num)
{
int resnum = 0;
bool digis[10] = {false , false ,false ,
false ,false , false ,false , false , false , false};
int power = 0;
int rem = 0;
while (num > 0)
{
rem = num % 10 ;
if(digis[rem] == false)
{
resnum = (int)(resnum + rem * pow(10 , power));
power++;
digis[rem] = true;
}
num = num / 10 ;
}
return resnum;
}
Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What is inheritance in simple words?
What is a class and object?
How do you use inheritance in unity?
Why oops is important?
What is encapsulation example?
Get me a number puzzle game-program
What do you mean by overloading?
Why do we use polymorphism?
What are the advantages of polymorphism?
why reinterpret cast is considered dangerous?
How to handle exception in c++, For example in a functions i am assigning memory to some variables and also in next instructions in am dividing one variable also. If this functions generates a error while allocating memory to those variable and also while dividing the variable if i divide by zero then catch block how it will identify that this error has cone from perticular instruction
What are the two different types of polymorphism?
What is purpose of inheritance?
What is pointer in oop?
What are the 5 oop principles?