当前位置:网站首页>[C language] question set of IX
[C language] question set of IX
2022-07-07 03:21:00 【InfoQ】
write in front
Question 41 → Sum of each digit of the number 『 recursive 』
sum += n % 10;// Find a bit sum = sum + n % 10
n = n / 10; // Erase a bit Question 42 → Bubble sort

Question 43 → Study Group
Question 44 → Multiplication of positive integers
Question 45 → Array element exchange
Question 41 の Code
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int print(unsigned int n)
{
// The reason for this is n>9 Because n<10 No matter what number we input, it will be the final sum of the sum
if (n > 9)
{
// Take the mold and get a bit , Divide by ten .
return print(n / 10) + n % 10;
}
else
{
return n;
}
}
int main(void)
{
unsigned int num = 0;
printf(" Please enter a number →");
scanf("%d", &num);
int ret = print(num);
printf("ret = %d\n", ret);
return 0;
}Question 42 の Code
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
void Bubble_Sort(int arr[],int sz)
{
int i = 0;
// Determine the number of times to sort
for (i = 0; i < sz - 1; i++)
{
// Number of times per exchange , Number of first exchanges n-1, successively ......
int j = 0;
// Prevent invalid loops , That is, when our array is bubble sorted .
int flag = 1;
// Determine the number of exchanges .
for (j = 0; j < sz - 1 - i; j++)
{
// Compare the first number with the second number , Exchange when the first number is greater than the second number .
if (arr[j] > arr[j + 1])
{
// Create temporary variables , swapping !
int change;
change = arr[j];
arr[j] = arr[j+1];
arr[j+1] = change;
flag = 0;
}
}
if (flag == 1)
{
break;
}
}
}
int main(void)
{
int i = 0;
// Reverse order of array
int arr[] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
//sz Is the size of the total elements of the array
int sz = sizeof(arr) / sizeof(arr[0]);
// Call function
Bubble_Sort(arr,sz);
for (i = 0; i < sz; i++)
{
printf("%d ", arr[i]);
}
return 0;
}Question 43 の Code
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main()
{
int i = 0;
int j = 0;// Loop initialization subscript
int arr[3][5] = { 0 };// That's ok - subject , Column - Student .
int sum = 0; // The total score of the current subject
int average = 0; // Total average score
int v[3]; // Average number of subjects
printf(" Please enter the grades of students in each subject :\n");
for (i = 0; i < 3; i++)
{
printf("\n A subject counts into 5 Second grade \n");
if (i == 0)
printf(" Mathematics :");
if (i == 1)
printf(" Chinese subject :");
if (i == 2)
printf(" English subjects :");
for (j = 0; j < 5; j++)
{
scanf("%d", &arr[i][j]); // Enter each student's grade in each subject
sum += arr[i][j]; // Calculate the total score of the current subject (sum)
}
v[i] = sum / 5; // Average score of current account , Divide the total score by 5
sum = 0; // Clear the total score of the current subject 0
}
printf("\n Math scores = %d\n Chinese achievement = %d\n English scores = %d\n", v[0], v[1], v[2]);
average = v[0] + v[1] + v[2];
printf(" average : %d\n", average / 3);
return 0;
}Question 44 の Code
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int Multiply(int a, int b)
{
if (b == 0)
{
return 0;
}
return a + Multiply(a, b - 1);// a + a * b
}
int main(void)
{
int i = 0;
int j = 0;
printf(" Please enter two numbers :");
scanf("%d %d", &i, &j);
Multiply(i, j);
printf("%d\n", Multiply(i, j));
return 0;
}Question 45 の Code
#include<stdio.h>
#define number 5
int main(void)
{
int i = 0;
int arr1[number] = { 1, 3, 5, 7, 9 };
int arr2[number] = { 2, 4, 6, 8, 10 };
for (i = 0; i < number; i++)
{
printf(" No exchange of previous values :arr1[%d] = %d\n",i + 1, arr1[i]);
}
for (i = 0; i < number; i++)
{
printf(" No exchange of previous values :arr2[%d] = %d\n", i + 1, arr2[i]);
}
printf("\n");
int sz = sizeof(arr1) / sizeof(arr1[0]);
for (i = 0; i < sz; i++)
{
int tmp;
tmp = arr1[i];
arr1[i] = arr2[i];
arr2[i] = tmp;
printf("arr1[%d] = %-2d ", i + 1, arr1[i]);
printf("arr2[%d] = %-2d\n", i + 1, arr2[i]);
}
return 0;
}边栏推荐
- Shell 编程基础
- Le tube MOS réalise le circuit de commutation automatique de l'alimentation principale et de l'alimentation auxiliaire, et la chute de tension "zéro", courant statique 20ua
- Left path cloud recursion + dynamic planning
- leetcode
- CVPR 2022 最佳论文候选 | PIP: 6个惯性传感器实现全身动捕和受力估计
- How to find file accessed / created just feed minutes ago
- Centerx: open centernet in the way of socialism with Chinese characteristics
- MOS transistor realizes the automatic switching circuit of main and auxiliary power supply, with "zero" voltage drop and static current of 20ua
- Cocos2d-x box2d physical engine compilation settings
- 杰理之在非蓝牙模式下,手机连接蓝牙不要跳回蓝牙模式处理方法【篇】
猜你喜欢

硬件之OC、OD、推挽解释

源代码保密的意义和措施
![[tools] basic concept of database and MySQL installation](/img/9c/626e42097050517a13a2ce7cdab1bb.jpg)
[tools] basic concept of database and MySQL installation

mos管實現主副電源自動切換電路,並且“零”壓降,靜態電流20uA
![Jericho is in non Bluetooth mode. Do not jump back to Bluetooth mode when connecting the mobile phone [chapter]](/img/ce/baa4acb1b4bfc19ccf8982e1e320b2.png)
Jericho is in non Bluetooth mode. Do not jump back to Bluetooth mode when connecting the mobile phone [chapter]

变量、流程控制与游标(MySQL)

CVPR 2022 最佳论文候选 | PIP: 6个惯性传感器实现全身动捕和受力估计

uniapp适配问题

2022.6.28

Form validation of uniapp
随机推荐
Hazel engine learning (V)
校招行测笔试-数量关系
Cocos2d-x Box2D物理引擎编译设置
[untitled]
Intelligent static presence detection scheme, 5.8G radar sensing technology, human presence inductive radar application
Jericho is in non Bluetooth mode. Do not jump back to Bluetooth mode when connecting the mobile phone [chapter]
【无标题】
杰理之开启经典蓝牙 HID 手机的显示图标为键盘设置【篇】
【colmap】已知相机位姿情况下进行三维重建
Household appliance industry under the "retail is king": what is the industry consensus?
sshd[12282]: fatal: matching cipher is not supported: [email protected] [preauth]
“去虚向实”大潮下,百度智能云向实而生
首届“量子计算+金融科技应用”研讨会在京成功举办
数学归纳与递归
SQL中删除数据
尚硅谷JVM-第一章 类加载子系统
腾讯云原生数据库TDSQL-C入选信通院《云原生产品目录》
An error in SQL tuning advisor ora-00600: internal error code, arguments: [kesqsmakebindvalue:obj]
杰理之RTC 时钟开发【篇】
Jerry's FM mode mono or stereo selection setting [chapter]