Thread: Recognize a pattern in number

  1. #1
    Registered User
    Join Date
    Nov 2021
    Posts
    2

    Recognize a pattern in number

    Hi:
    I want to make a program that recognizes if a given number is "waving", that is, if it is of the form ababababa...
    Nothing really comes into mind, any help is appreciated.

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    You can read the number as a string and process it that way.
    You can convert the integer to a string and process it that way.
    You can use the mod operator (% 10) to strip off the last digit one at a time.

    Also consider:
    * Is a single digit wavey?
    * Are two digits wavey?
    * Is a number wavey if a == b?
    A little inaccuracy saves tons of explanation. - H.H. Munro

  3. #3
    Registered User
    Join Date
    Nov 2021
    Posts
    2
    How can I read it as a string? I do not know the length of the number beforehand.

  4. #4
    Registered User
    Join Date
    Apr 2021
    Posts
    140
    Are you taking input from the user? Then the number is a string when you read it, and you have to somehow convert it to an int or float during the input process.

    Are you computing the number, or are you receiving the number as a parameter? Then you can use sprintf to write the number into a string buffer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 03-31-2015, 05:58 PM
  2. Number Pattern Problem?
    By Frank1234 in forum C++ Programming
    Replies: 3
    Last Post: 03-25-2013, 01:55 PM
  3. Number pattern program help
    By nsriv in forum C Programming
    Replies: 7
    Last Post: 12-13-2012, 07:55 AM
  4. odd and even number pattern
    By christianB in forum C Programming
    Replies: 31
    Last Post: 07-18-2011, 01:04 PM
  5. Recognize if the floating number is valid or not in C
    By feb0590 in forum C Programming
    Replies: 3
    Last Post: 04-16-2009, 04:57 AM

Tags for this Thread