덧셈 & 나눗셈
                                            
 7829 단어  &
                    
 1 #include <stdio.h>
 2 
 3 //   
 4 int div(int loperand, int roperand)
 5 {
 6     int cnt = 0;
 7     while (loperand > roperand)
 8     {
 9         cnt++;
10         loperand -= roperand;
11     }
12 
13     return cnt;
14 }
15 
16 //    
17 int getRemainder(int loperand, int roperand)
18 {
19     while (loperand > roperand)
20         loperand -= roperand;
21 
22     return loperand;
23 }
24 
25 //   
26 unsigned int add(unsigned int loperand, unsigned int roperand)
27 {
28     int currentbit = 0, carrybit = 0;
29     unsigned int res = 0;
30     int cnt = 0;
31     int len = sizeof(loperand) << 3;
32 
33     while (cnt < len)
34     {
35         int tmp = carrybit;     //        
36         carrybit = 0;
37         //        
38         currentbit = (loperand & 0x01) ^ (roperand & 0x01);
39         //             
40         if (currentbit == 0 && (loperand & 0x01) == 1)
41             carrybit = 1;
42         else if (currentbit == 1 && tmp == 1)
43             carrybit = 1;
44         currentbit ^= tmp;
45         //     
46         res |= (currentbit << cnt);
47         cnt++;
48         loperand >>= 1, roperand >>= 1;
49     }
50 
51     return res;
52 }
53 int main()
54 {
55     int num1 = 65535;
56     int num2 = 65535;
57 
58     printf("%d + %d = %d", num1, num2, add(num1, num2));
59 
60     return 0;
61 }
                이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[Angular JS: Up & Running] 04장_양식, 입력 및 서비스양식 상태 이름 $invalid 인증이 통과되지 않은 경우 (필수 인증, 최소 길이 검증 등) AngularJS는 양식에 $invalid 속성을 설정합니다. $valid AngularJS의 모든 양식 상태는 $pri...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.