当前位置:网站首页>[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;
}边栏推荐
- 图形化工具打包YOLOv5,生成可执行文件EXE
- QT Bluetooth: qbluetooth DeviceInfo
- Jerry's FM mode mono or stereo selection setting [chapter]
- Matlab Error (Matrix dimensions must agree)
- 杰理之发射端在接收端关机之后假死机【篇】
- 装饰设计企业网站管理系统源码(含手机版源码)
- [swift] learning notes (I) -- familiar with basic data types, coding styles, tuples, propositions
- Shell programming basics
- Codeforces Round #264 (Div. 2) C Gargari and Bishops 【暴力】
- 从 1.5 开始搭建一个微服务框架——日志追踪 traceId
猜你喜欢

mos管實現主副電源自動切換電路,並且“零”壓降,靜態電流20uA

源代码保密的意义和措施

Stored procedures and functions (MySQL)

Form validation of uniapp

Utilisation de la promesse dans es6

Change your posture to do operation and maintenance! GOPs 2022 Shenzhen station highlights first!

Another million qubits! Israel optical quantum start-up company completed $15million financing

装饰设计企业网站管理系统源码(含手机版源码)

图形化工具打包YOLOv5,生成可执行文件EXE
![[cpk-ra6m4 development board environment construction based on RT thread studio]](/img/08/9a847c73d6da6fc74d84af56897752.png)
[cpk-ra6m4 development board environment construction based on RT thread studio]
随机推荐
The whole process of knowledge map construction
【安全的办公和生产力应用程序】上海道宁为您提供ONLYOFFICE下载、试用、教程
Utilisation de la promesse dans es6
SQL中删除数据
Change your posture to do operation and maintenance! GOPs 2022 Shenzhen station highlights first!
HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
leetcode-02(链表题)
“零售为王”下的家电产业:什么是行业共识?
oracle连接池长时间不使用连接失效问题
Cryptography series: detailed explanation of online certificate status protocol OCSP
【达梦数据库】备份恢复后要执行两个sql语句
c语言字符串排序
Jerry's broadcast has built-in flash prompt tone to control playback pause [chapter]
图形化工具打包YOLOv5,生成可执行文件EXE
Use of promise in ES6
迷失在MySQL的锁世界
unrecognized selector sent to instance 0x10b34e810
Starting from 1.5, build a micro Service Framework -- log tracking traceid
Shell 编程基础
Analysis of USB network card sending and receiving data