当前位置:网站首页>[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;
}
边栏推荐
- [shutter] shutter layout component (opacity component | clipprect component | padding component)
- The source code of the daily book analyzes the design idea of Flink and solves the problems in Flink
- Riding the wind of "cloud native" and stepping on the wave of "digitalization", new programmer 003 starts pre-sale
- [Jianzhi offer] 56 - ii Number of occurrences of numbers in the array II
- Blue Bridge Cup Winter vacation homework (DFS backtracking + pruning)
- Landingsite eband B1 smoke test case
- C language, to achieve three chess games
- The web version of xshell supports FTP connection and SFTP connection
- D4: unpaired image defogging, self enhancement method based on density and depth decomposition (CVPR 2022)
- 情感计算与理解研究发展概述
猜你喜欢
LandingSite eBand B1冒烟测试用例
Official announcement! The golden decade of new programmers and developers was officially released
How do I access the kubernetes API?
The neo4j skill tree was officially released to help you easily master the neo4j map database
Redis distributed lock failure, I can't help but want to burst
Ransack组合条件搜索实现
Pip install whl file Error: Error: … Ce n'est pas une roue supportée sur cette plateforme
From personal heroes to versatile developers, the era of programmer 3.0 is coming
Blue Bridge Cup Winter vacation homework (DFS backtracking + pruning)
【零基础一】Navicat下载链接
随机推荐
Etcd Raft 协议
Today, I met a Alipay and took out 35K. It's really sandpaper to wipe my ass. it's a show for me
20220702 how do programmers build knowledge systems?
[Jianzhi offer] 56 - ii Number of occurrences of numbers in the array II
Lightgbm principle and its application in astronomical data
From "bronze" to "King", there are three secrets of enterprise digitalization
Official announcement! The golden decade of new programmers and developers was officially released
【剑指 Offer 】56 - II. 数组中数字出现的次数 II
Riding the wind of "cloud native" and stepping on the wave of "digitalization", new programmer 003 starts pre-sale
《Just because》阅读感受
Ransack combined condition search implementation
scrcpy这款软件解决了和同事分享手机屏幕的问题| 社区征文
#include<>和#include“”的区别
C语言,实现三子棋小游戏
Cardinality sorting (detailed illustration)
The failure rate is as high as 80%. What should we do about digital transformation?
关于PHP-数据库的 数据读取,Trying to get property 'num_rows' of non-object?
[C language] [sword finger offer article] - replace spaces
Leetcode theme [array] -169- most elements
Etcd raft protocol