C-language classical algorithm-the odd number of 0-7 can be composed

Source: Internet
Author: User

Title: An odd number of 0-7 can be composed.

Algorithm idea:
This problem is actually a permutation of the problem, set the number of SUN=A1A2A3A4A5A6A7A8,A1-A8 to represent this number of a bit of the value,
When the last digit of a number is odd, it must be an odd number, no matter what number is in front of it. If the last digit is an even number,
The number must be even.
A1-a8 can take 0-7 of this eight number, the first number is not 0.
From this number to one count to the number of 8 digits to start counting odd numbers:
1. When only one digit is the last of the number, the odd number is 4
2. When the number is two digits, the odd number is 4*7=28
3. When the number is three digits, an odd number is: 4*8*7=224



8. When the number is eight digits, the odd number is: 4*8*8*8*8*8*8*7 (the last one to the first digit)

C Language Program code:

1#include <stdio.h>2 intMainintAGRC,Char*agrv[])3 {4     Longsum =4, S =4;//the initial value of sum is 4, and only one digit is an odd number of 45     intJ;6      for(j =2; J <=8; J + +)7     {    8printf"the number of%d digits is odd%ld\n", J-1, s);9         if(J <=2)TenS *=7; One         Else AS *=8; -Sum + =s;  -     } theprintf"the number of%d digits is odd%ld\n", J-1, s); -printf"The total number of odd numbers is:%ld\n", sum); -System"Pause"); -     return 0; +}

C-language classical algorithm-the odd number of 0-7 can be composed

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.