当前位置:网站首页>Two hundred questions in C language (0 basic continuous update) (1~5)
Two hundred questions in C language (0 basic continuous update) (1~5)
2022-08-11 06:57:00 【Lamb said test!】
First, take the easiest one first!It is suitable for pure novice, and the boss can take a detour.
Output hello world!Let's say hello to the world!
#includeint main(){printf("Hello World!");return 0;}
Don't go when you see this!Let's gradually stack up the difficulty, okay?
Second, if m is a three-digit number, write the three-digit number formed by the reverse order of the ones, tens, and hundreds of m (for example: 123 is reversed to 321)
#includeint main(){int n = 123,t;do{t = n%10; //Remove the single digit of the right numberprintf("%d",t);n/=10; //Discard the right number and continue the loop}while(n);//n is equivalent to n!=0 Continue processing as long as the number of significant digits has not been processedreturn 0 ;}
3. Known int x=10, y=12; write an expression that exchanges the values of x and y with each other!
(1) The easiest way!Use the third variable and then swap
#includeint main(){int x=10,y=12,t;//Define the third variable t exchanget=x; x=y; y=t;//swapprintf("x=%d y=%d",x,y);return 0;}
(2) The second use of addition and subtraction exchange is also easy to understand!
#includeint main(){int x=10,y=12;x=x+y;y=x-y;x=x-y;printf("x=%d y=%d",x,y);return 0;}
(3) The third is to use bit operations, it doesn't matter if you don't understand!I will explain in detail later
#includeint main(){int x=10,y=12;x=x^y;y=x^y;x=x^y;printf("x=%d y=%d",x,y);return 0;}
4. Enter a character to determine whether it is an uppercase letter, if so, convert it to lowercase, otherwise do not convert it.Then output the resulting character.
#includeint main(){char ch; //Define a variable to accept the value read by the keyboardch=getchar();if(ch>='A'&&ch<='Z')// Determine whether it is uppercase{ch-=32;printf("%c",ch); //Output the converted a} //Remember that the ASCII code of uppercase A is 65, a is 97, and the difference between them is 32;elseprintf("%c",ch); // unchangedreturn 0;}
5. Judgment of odd and even numbers
#includeint main(){int num;scanf("%d",&num);if(num%2==0) //It must be even if divisible by 2printf("%d is even",num);else //then it's oddprintf("%d is odd",num);return 0;}
The five basic questions are updated here today. If you have any questions, please leave a message. The editor-in-chief has just entered the freshman year and is learning the advanced part of C language!Two hundred questions will be continuously updated later
If you find it useful, like, follow, and bookmark!
边栏推荐
猜你喜欢
随机推荐
项目笔记——随机2
Apache Fink 文件上传漏洞复现及利用
OpenGL中glGenBuffers glBindBuffer glBufferData的理解
UML 类图之间的关系
Redis学习笔记【二】
C语言-6月12日-字符替换问题,将一个‘ ’替换为2个‘#’
【LeetCode-13】罗马数字转整数
【LeetCode-414】第三大的数
非对称加密——网络安全
中小微企业需要使用SSL证书吗?
C语言-6月8日-给定一个字符数组‘i am a student’ 统计字符a的个数并进行输出
C语言实现扫雷游戏
GoAhead Server 环境变量注入(CVE-2021-42342)漏洞复现
Unity C# 面试题、知识点总结
C语言-7月31日-指针的总结以及typedef关键字
无胁科技-TVD每日漏洞情报-2022-8-8
分页查询模型
【LeetCode-455】方法饼干
2022年全国职业技能大赛网络安全竞赛试题B模块自己解析思路(3)
【LeetCode-162】寻找峰值