当前位置:网站首页>[C question set] of V
[C question set] of V
2022-07-02 22:01:00 【InfoQ】
write in front
Question 21 → Suppose you enter a number 5, Realization 1+2+3+4+5=16, Similarly, input any number to produce the sum of each number ( Recursive method implementation )
- Every recursive function should only make a limited number of recursive calls , Otherwise it will enter a dead end , Never quit , Such a procedure is meaningless .
- There are restrictions, When this restriction is met , Recursion will not continue .
- After every recursive callGetting closer to this limit.
Question 22 → Exchange two values with a pointer , Temporary variables cannot be created for exchange replacement
Question 23 → Write code , Demonstrate the movement of multiple characters from both ends , Converging in the middle .( One cycle delay 1s Then clear the screen , Finally print out the characters )
char arr1[] = "Cyuyuanyyds";
char arr2[] = "###########";
Sleep();// The time delay function , Be careful :S Use capital letters
system("cls");// Screen clearing function
Question 24 → use switch Branch statements enter Monday through Sunday , If you enter a range other than Monday to Sunday, print eroor (switch Statements for )
switch( expression )
{
case Constant expression 1:
sentence 1;
case Constant expression 2:
sentence 2;
…
case Constant expression n:
sentence n;
default :
By default, statement blocks ;
}
Question 25 → Please input a password , Then input Y Yes, confirm the password ,N Yes, confirmation failed
Question 21 code
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int face(int n)
{
if (n <= 1)
return 1;
else
return (n+face(n - 1));// Attention priority
}
int main(void)
{
int n;
printf(" Please enter your number :");
scanf("%d", &n);
int ret = face(n);
printf("N = %d\n", ret);
return 0;
}
Question 22 code
#include<stdio.h>
void swap(int *x, int *y)
{
// Bitwise XOR hypothesis yes x = 1,y = 2
*x ^= *y;//x = x^y // 0001 ^ 0010 = 0011 = 3 here x = 3
*y ^= *x;//y = x^y // 0011 ^ 0010 = 0001 = 1 here y = 1
*x ^= *y;//x = x^y // 0011 ^ 0001 = 0010 = 2 here x = 2 result x = 2,y = 1
}
int main(void)
{
int a, b;
printf(" Please enter two numbers :");
scanf("%d %d", &a, &b);
printf("a,b Exchange before : a = %d,b = %d\n", a, b);
swap(&a, &b);
printf("a,b After exchanging : a = %d,b = %d\n", a, b);
return 0;
}
Question 23 code
#include<stdio.h>
#include<string.h>//strlen Long header file
#include<windows.h>//system(""); Execute command header file
int main(void)
{
char arr1[] = "nageshijieshimeng";
char arr2[] = "#################";
int left = 0;// Subscript Access subscript elements from 0 Start
int right = strlen(arr1) - 1;// Length string Subscript Subscripts are less than the number of elements 1, So you have to subtract 1
while (left <= right)// When subscript <= Subscript ( character ) Then stop the cycle
{
arr2[left] = arr1[left]; // hold [arr1]n=[arr2]# On the left left First character
arr2[right] = arr1[right];// hold [arr2]g=[arr2]# On the right right First character
printf("%s\n", arr2);
Sleep(1000); // Delay 1000ms = 1s
system("cls");// Clear the current screen
left++;
right--;
}
printf("%s\n", arr2);// Finally print out the result
return 0;
}
Question 24 code
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main(void)
{
int input = 0;
printf("Please enter:");
scanf("%d", &input);
switch (input)
{
case 1:
printf("Monday\n");
break;
case 2:
printf("Tuesday\n");
break;
case 3:
printf("Wednesday\n");
break;
case 4:
printf("Thursday\n");
break;
case 5:
printf("Friday\n");
break;
case 6:
printf("Saturday\n");
break;
case 7:
printf("Sunday\n");
break;
default:
printf("eroor\n");
}
}
Question 25 code
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main(void)
{
char password[20] = { 0 };
int ret = 0;
printf(" Please input a password :");
//password It's an array name , The array name itself is already addressed .
scanf("%s", password);
// When we program scanf The function has... When reading the buffer \n, So we should take \n This character of is read ! Note that the buffer will remain \n
int ch;
while ((ch = getchar()) != '\n');// build while Loop until the buffer '\n' Finished reading
printf(" Please confirm the password (Y/N):");
ret = getchar();// After reading , Proceed again getchar() An input to
if (ret == 'Y')
{
printf(" Confirm success !\n");
}
if (ret == 'N')
{
printf(" Confirmation failed !\n");
}
if (ret != 'Y'&&'N')
{
printf(" The input format is incorrect !\n");
}
return 0;
}
边栏推荐
- 暑期第一周总结
- Structure array, pointer and function and application cases
- Etcd Raft 协议
- How do I access the kubernetes API?
- 【零基础一】Navicat下载链接
- MySQL learning record (8)
- VictoriaMetrics 简介
- treevalue——Master Nested Data Like Tensor
- How to write a good program when a big book speaks every day?
- Ransack combined condition search implementation
猜你喜欢
![[shutter] shutter layout component (wrap component | expanded component)](/img/a7/824a990235fc5ce67841ebdcf001fb.jpg)
[shutter] shutter layout component (wrap component | expanded component)

treevalue——Master Nested Data Like Tensor

MySQL learning record (8)

Find objects you can't see! Nankai & Wuhan University & eth proposed sinet for camouflage target detection, and the code has been open source

MySQL learning record (2)

Off chip ADC commissioning record

Redis distributed lock failure, I can't help but want to burst

scrcpy这款软件解决了和同事分享手机屏幕的问题| 社区征文

Daily book -- analyze the pain points of software automation from simple to deep

Gbase8s database type
随机推荐
The neo4j skill tree was officially released to help you easily master the neo4j map database
TinyMCE visual editor adds Baidu map plug-in
treevalue——Master Nested Data Like Tensor
Evolution of messaging and streaming systems under the native tide of open source cloud
What is it that makes you tremble? Those without fans can learn
MySQL learning record (7)
"New programmer 003" was officially launched, and the cloud native and digital practical experience of 30+ companies such as Huawei and Alibaba
Redis分布式锁故障,我忍不住想爆粗...
如何防止你的 jar 被反编译?
Interpretation of CVPR paper | generation of high fidelity fashion models with weak supervision
100 important knowledge points that SQL must master: management transaction processing
Read a doctor, the kind that studies cows! Dr. enrollment of livestock technology group of Leuven University, milk quality monitoring
20220702-程序员如何构建知识体系?
scrcpy这款软件解决了和同事分享手机屏幕的问题| 社区征文
[shutter] shutter layout component (wrap component | expanded component)
【剑指 Offer】56 - I. 数组中数字出现的次数
读博士吧,研究奶牛的那种!鲁汶大学 Livestock Technology 组博士招生,牛奶质量监测...
【leetcode】1380. Lucky number in matrix
Cardinality sorting (detailed illustration)
Destroy in beforedestroy invalid value in localstorage