Onge C Introduction to the third week of programming topic "Digital Eigenvalue"

Source: Internet
Author: User

Topic content:

It is a common coding algorithm to find the eigenvalues of numbers, and the odd-even feature is a simple characteristic value. For an integer, each digit is numbered from bit to digit, number 1th, 10 digit is 2nd, and so on. This integer number on the nth bit is recorded as x, if the parity of X and N is the same, write down a 1, otherwise write down a 0. 0 and 1 of the parity of the corresponding bit are recorded in the order of integers, and a binary number is formed. For example, for 342315, this binary number is 001101.

The calculation here can be expressed in the following table:

Digital

3

4

2

3

1

5

Digital digits

6

5

4

3

2

1

Digital parity

Odd

I

I

Odd

Odd

Odd

Digital odd-even

I

Odd

I

Odd

I

Odd

Parity consistent

0

0

1

1

0

1

Bits value

32

16

8

4

2

1

By adding the bit value of 1 bits to the bits value, you get the result 13.

Your program reads a nonnegative integer, the range of integers is [0,100000], and then calculates the binary number that represents the parity by the above algorithm, outputting its corresponding decimal value.

Input format:

A nonnegative integer in which the range of integers is [0,100000].

Output format:

An integer that represents the result of the calculation.

Input Sample:

342315

Sample output:

13

My full score through the answer, written in this convenient later view

#include <stdio.h>#include<math.h>intMain () {intnum; intCount=0; intA=0; intdig=0; scanf ("%d",&num);  Do{Count++; A=num%Ten; if((a+count)%2==0) {Dig=dig+pow (2, count-1); } num/=Ten; } while(num>0); printf ("%d", Dig); return 0;}

PS: Numerical parity and digital parity compare and contrast, equivalent to the sum of two numbers is an even number.

This is my own mistake to think of, think that others are so, and then look at the discussion area, found that many people are the first two numbers are a single judgment, and finally a comprehensive judgment, so very troublesome. and netizens Ikeltis earlier than I thought of this idea, sent to talk about the area also by Weng Teacher's micro Bo praise, think oneself is also independent thinking of this way, inexplicable feel some encouragement, haha, stay this article memorial.

Attach the user Ikeltis code (without consent, forgive me)
/** Train of thought: digital parity and digit parity are recorded as 1, equivalent to the sum of numbers and digits is even when recorded as 1 * do not know the C language index how to ask, with H did the multiplicative*/#include<stdio.h>intMain () {intn=1; intH=1; intnum; intflag=0; scanf ("%d",&num); while(num! =0) { if((num+n)%2==0) {flag= Flag +h; } N++; Num= num/Ten;//delete the last digit.h=h*2; } printf ("%d\n", flag); return 0;}

Onge C Introduction to the third week of programming topic "Digital Eigenvalue"

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.