当前位置:网站首页>[C language] PTA 7-47 binary leading zero
[C language] PTA 7-47 binary leading zero
2022-07-29 04:29:00 【LastWhisperw】
Inside the computer, all the values are expressed in binary . A decimal number , such as 24, In a 32 The computer interior of bit is expressed as 00000000000000000000000000011000. You can see , Count from the left , At the first 1 Before , Yes 27 individual 0. We put these 0 Zero called leading .
Now? , Your task is to write a program , Enter an integer , Output in 32 The number of leading zeros in bit expression .
Input format :
An integer , stay 32 An integer can be expressed in a range of bits .
Output format :
An integer , The expression input is expressed as a 32 Bit binary number , At the first 1 Previous 0 The number of .
sample input :
256No blank lines at the end
sample output :
23No blank lines at the end
Their thinking : There is i, Make a given number n stay 2^(i-1) and 2^i Between . Find that i, Output 32-i. If n It's a negative number , When storing, the first place is 1.
#include<stdio.h>
#include<math.h>
int main(){
int n;
int i=0;
scanf("%d",&n);
if(n>=0){
while(pow(2,i)<=n){
i++;
}
}
else{
i=32;
}
printf("%d",32-i);
return 0;
}边栏推荐
- Webrtc realizes simple audio and video call function
- Pytorch GPU and CPU models load each other
- 【Express连接MySQL数据库】
- 通过js来实现一元二次方程的效果,输入a,b,c系数后可计算出x1和x2的值
- C语言:联合体知识点总结
- Introduction and examples of parameters in Jenkins parametric construction
- Can you really write restful API?
- Leetcode 686. KMP method of repeatedly superimposing strings (implemented in C language)
- Interview notes of a company
- Mpc5744p introduction and opensda firmware update
猜你喜欢

Hengxing Ketong invites you to the 24th China expressway informatization conference and technical product exhibition in Hunan

TypeError: Cannot read properties of undefined (reading ‘then‘)

MySQL - clustered index and secondary index

redux快速上手

C language force buckle question 61 of the rotating list. Double ended queue and construction of circular linked list

Common components of solder pad (2021.4.6)

Pycharm reports an error when connecting to the virtual machine database

不会就坚持60天吧 神奇的字典

Can you really write restful API?

The third ACM program design competition of Wuhan University of Engineering
随机推荐
Update learning materials daily
The daily life of programmers
Not for 60 days, magical dictionary
Kotlin's list, map, set and other collection classes do not specify types
Make a virtual human with zego avatar | virtual anchor live broadcast solution
Leetcode 686. KMP method of repeatedly superimposing strings (implemented in C language)
C language: structure simple syntax summary
DASCTF2022.07赋能赛
Whether the modification of import and export values by ES6 and commonjs affects the original module
Two forms of softmax cross entropy + numpy implementation
Christmas tree web page and Christmas tree application
Pytoch automatic mixing accuracy (AMP) training
Machine vision series 3:vs2019 opencv environment configuration
Machine vision Series 1: Visual Studio 2019 dynamic link library DLL establishment
通过js来实现一元二次方程的效果,输入a,b,c系数后可计算出x1和x2的值
Differences and principles of bio, NiO and AIO
6.pytest生成allure报告
论pyscript使用感想(实现office预览)
14.haproxy+keepalived负载均衡和高可用
[material delivery UAV] record (ROS + Px4 + yolov5 + esp8266 + steering gear)