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


Please Help Members By Posting Answers For Below Questions

What is difference between polymorphism and inheritance?

617


What does I oop mean?

616


What is and I oop mean?

618


Get me an image implementation program.

1557


Describe these concepts: Polymorphism, Inheritance and Abstraction.

612






What is a class and object?

598


What are the benefits of oop?

604


What is encapsulation with real life example?

571


What is polymorphism in oops with example?

530


What do you mean by variable?

577


How oops is better than procedural?

586


Can you name some types of inheritance?

640


What is the full form of oops?

608


Why is abstraction used?

604


What type of loop is a for loop?

682