当前位置:网站首页>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!
边栏推荐
猜你喜欢
随机推荐
C语言-7月21日-指针的深入
Deep Learning Matlab Toolbox Code Comments
Msfvenom生成后门及运用
(三)软件测试理论(了解软件的缺陷知识)
Threatless Technology-TVD Daily Vulnerability Intelligence-2022-8-6
Login error in mysql: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)ERROR
程序集与反射技术(C#)
OpenGL中glGenBuffers glBindBuffer glBufferData的理解
JVM学习四:垃圾收集器与内存回收策略
C语言-6月10日-my_strcat函数的编写
Unity 数字跳字功能
Redis学习笔记【三】
SSL证书为什么要选付费?
【转】Unity 内置渲染管线、SRP、URP、HDRP区别
2022年全国职业技能大赛网络安全竞赛试题B模块自己解析思路(9)
2022年全国职业技能大赛网络安全竞赛试题B模块自己解析思路(7)
处理eking.Devos勒索病毒防范解密恢复操作攻略
无胁科技-TVD每日漏洞情报-2022-7-27
VirtualAPK初探
【LeetCode-202】快乐数









