Classical C Language Test-search for multiple-digit repetition numbers and times

Source: Internet
Author: User

Classical C Language Test-search for multiple-digit repetition numbers and times
Input a multi-digit integer on the keyboard and use the program to check whether there are repeated numbers and repeated numbers in the number.

Example: input: 1122431

Print result:

1 repeat three times

2 repeat twice,

Code:

# Include

 
  
// Search for multiple-digit repeated numbers and times int main () {long n = 0; printf ("enter a multiple-digit number:"); scanf ("% d", & n ); int s [10] = {0}; // record the number of occurrences of the corresponding number while (n> 0) {s [n % 10] = s [n % 10] + 1; // 1123 n = n/10 ;} // print the number of times greater than 1 in the traversal array int I = 0; for (I = 0; I <10; I ++) {if (s [I]> 1) {printf ("% d repeated % d times \ n", I, s [I]) ;}} return 0 ;}

 
Running result:

1122431

1 repeat three times

2 repeat twice,


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.