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

Why is encapsulation used?

582


What is persistence in oop?

677


Why we use classes in oop?

587


Why do pointers exist?

665


What is property in oops?

571






What are the benefits of polymorphism?

628


How to hide the base class functionality in Inheritance?

642


Why do we need oop?

671


What does sksksk mean in text slang?

1542


What is interface? When and where is it used?

1667


What is oops in programming?

570


what type of question are asked in thoughtworks pair programming round ?

1766


What is super in oop?

601


What is an interface in oop?

600


Write a program to compute for numeric grades for a course. The course records are in a file that will serve as the input file. The input file is in exactly the following format: Each line contains a student's first name, then one space, then ten quiz scores all on one line. The quiz scores are in whole number and are separated by one space. Your program will take it input from this file and sends it output to a second file. The data in the output file will be exactly the same as the data in the input file except that there will be one additional number (of type double) at the end of each line. This number will be the average of the student's ten quiz scores. Use at least one function that has file streams as all or some of its arguments.

2580