当前位置:网站首页>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!
边栏推荐
猜你喜欢
随机推荐
[HTB]渗透Backdoor靶机
OpenGL中glGenBuffers glBindBuffer glBufferData的理解
C语言-6月10日-my_strcpy函数的编写
无胁科技-TVD每日漏洞情报-2022-7-29
mongo-express 远程代码执行漏洞复现
lua杂记
【LeetCode-13】罗马数字转整数
C语言-内存操作函数
无胁科技-TVD每日漏洞情报-2022-8-2
2022年全国职业技能大赛网络安全竞赛试题B模块自己解析思路(1)
C语言实现三子棋(代码详解)
Vulnhub靶机--Chronos
无胁科技-TVD每日漏洞情报-2022-8-8
Redis学习笔记【三】
(二)软件测试理论(*重点用例方法编写)
【LeetCode-205】同构字符串
无胁科技-TVD每日漏洞情报-2022-7-27
C语言-7月21日-指针的深入
IP证书申请
Unity 使用双缓冲实现一个好用的计时器









