当前位置:网站首页>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!
边栏推荐
猜你喜欢
随机推荐
【LeetCode-349】两个数组的交集
【LeetCode-147】对链表进行插入排序
无胁科技-TVD每日漏洞情报-2022-7-18
SSL证书为什么要选付费?
【LeetCode-162】寻找峰值
Project Notes - Random 2
Threatless Technology-TVD Daily Vulnerability Intelligence-2022-8-6
无胁科技-TVD每日漏洞情报-2022-7-19
C-动态内存管理
分布式事物学习
无胁科技-TVD每日漏洞情报-2022-7-25
unity小技巧
项目笔记——随机2
Vulnhub靶机--DC8
C语言-6月8日-给定一个字符数组‘i am a student’ 统计字符a的个数并进行输出
无胁科技-TVD每日漏洞情报-2022-8-6
【LeetCode-205】同构字符串
C语言预处理
电脑录屏的简单方法
C语言实现扫雷游戏