Jump to content

Help finding duplicate digits

- - - - -

  • Please log in to reply
1 reply to this topic

#1
skastu01

skastu01

    Newbie

  • Members
  • PipPip
  • 27 posts
Hi -
I need help writing a program which will read in a long int and check whether any of the digits in the number appear more than once.

I need to use an array of type bool which is indexed to 10 and initially set to false. I have written this as below:
int main()

{

int long i,n, num;

bool digits_seen[10];


for (i = 0; i <= 9; i++) {

digits_seen[i]=false;

cout<<digits_seen[i];

}


When the user enters his number n, the program should read in the entire integer and then examine each digit in n and set the appropriate index entry in the array to true to indicate that it has been seen. This is where I am seeking advice. Thanks.

#2
Groogy

Groogy

    Programmer

  • Members
  • PipPipPipPip
  • 183 posts
You can get the integer value by using cin >> n. And to get the value of digits. I have never tried but I think you are looking after this: Cprogramming.com - Tutorials - Bitwise Operators and Bit Manipulations in C and C++
My Code Blog - My Github - Ascension Project - Madness Script Project - Simple-Garbage-Collector Project
There is bound to be something useful somewhere.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users