Thread: Disappearing Numbers

  1. #1
    Registered User
    Join Date
    Nov 2003

    Disappearing Numbers

    Does any programmer know how to display a set of numbers 1-9, on the screen, Then when a User inputs a number(i.e. 5) it will then display ( 1 2 3 4 6 7 8 9) thus having 5 not show at all. And is there any way that you can match numbers in a two-dimensional array for if they are greater than 9, or if they are repeating.

  2. #2
    Registered User
    Join Date
    Feb 2004
    Yes to all three questions. Though how you can choose to go about each is different. The simplest way to go about the first is simply to print out the numbers and ignore the number that was input.
    for (int n = 1; n < 10; n++) {
        if (n == input)
        cout<< n <<'\n';
    A similar method can be used for finding numbers greater than 9 in an array.
    int n = 0;
    for (int i = 0; i < nrow; i++) {
        for (int j = 0; j < ncol; j++) {
            if (array[i][j] > 9)
    Finding duplicate numbers is slightly more difficult, but it is made trivial with the standard map container. Simply create a frequency map.
    map<int, int> frequency;
    for (int i = 0; i < nrow; i++) {
        for (int j = 0; j < ncol; j++)
            frequency[ array[i][j] ]++;
    // Now map contains the unique values and the number of those values. Finding duplicates in this data structure is simple.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing unique numbers to an array
    By yardy in forum C Programming
    Replies: 6
    Last Post: 12-27-2006, 09:15 PM
  2. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  3. Adding Line numbers in Word
    By Mister C in forum A Brief History of
    Replies: 24
    Last Post: 06-24-2004, 08:45 PM
  4. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM