当前位置:网站首页>[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;
}
边栏推荐
- Error in PIP installation WHL file: error: is not a supported wheel on this platform
- PIP audit: a powerful security vulnerability scanning tool
- [use of pointer and pointer and array]
- 一周生活
- 地理探测器原理介绍
- D4:非成对图像去雾,基于密度与深度分解的自增强方法(CVPR 2022)
- 如何访问kubernetes API?
- Chargement de l'image pyqt après décodage et codage de l'image
- The neo4j skill tree was officially released to help you easily master the neo4j map database
- 100 important knowledge points that SQL must master: using cursors
猜你喜欢
![[staff] Sibelius 7.5.1 score software installation (software download | software installation)](/img/1a/4932a7931c54248c065cf8a1462d34.jpg)
[staff] Sibelius 7.5.1 score software installation (software download | software installation)

From "bronze" to "King", there are three secrets of enterprise digitalization

Sql service intercepts string

GEE:(二)对影像进行重采样
![[CV] Wu Enda machine learning course notes | Chapter 12](/img/c8/9127683b6c101db963edf752ffda86.jpg)
[CV] Wu Enda machine learning course notes | Chapter 12
![[use of pointer and pointer and array]](/img/dd/8017215c54aebcdf5c67e46e795d3b.jpg)
[use of pointer and pointer and array]

How to write a good program when a big book speaks every day?

The source code of the daily book analyzes the design idea of Flink and solves the problems in Flink
![[shutter] shutter layout component (wrap component | expanded component)](/img/a7/824a990235fc5ce67841ebdcf001fb.jpg)
[shutter] shutter layout component (wrap component | expanded component)

MySQL learning record (9)
随机推荐
Destroy in beforedestroy invalid value in localstorage
Browser - clean up the cache of JS in the page
Pyqt picture decodes and encodes and loads pictures
关于PHP-数据库的 数据读取,Trying to get property 'num_rows' of non-object?
Unity3D学习笔记4——创建Mesh高级接口
MySQL installation failed -gpg verification failed
读博士吧,研究奶牛的那种!鲁汶大学 Livestock Technology 组博士招生,牛奶质量监测...
GEE:(二)对影像进行重采样
Sql service intercepts string
The failure rate is as high as 80%. What should we do about digital transformation?
Ransack combined condition search implementation
Error in PIP installation WHL file: error: is not a supported wheel on this platform
Read a doctor, the kind that studies cows! Dr. enrollment of livestock technology group of Leuven University, milk quality monitoring
Blue Bridge Cup Eliminate last one (bit operation, code completion)
在beforeDestroy中销毁localStorage中的值无效
一周生活
[CV] Wu Enda machine learning course notes | Chapter 12
[C language] [sword finger offer article] - replace spaces
kubernetes资源对象介绍及常用命令(四)
Cardinality sorting (detailed illustration)