当前位置:网站首页>[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;
}边栏推荐
- 迷失在MySQL的锁世界
- Jerry's transmitter crashed after the receiver shut down [chapter]
- Shell programming basics
- Decoration design enterprise website management system source code (including mobile source code)
- oracle连接池长时间不使用连接失效问题
- netperf 而网络性能测量
- SQL中删除数据
- HDU ACM 4578 Transformation-&gt; Segment tree - interval change
- 【达梦数据库】添加自动收集统计信息的任务
- Shangsilicon Valley JVM Chapter 1 class loading subsystem
猜你喜欢

Nuggets quantification: obtain data through the history method, and use the same proportional compound weight factor as Sina Finance and snowball. Different from flush

MOS transistor realizes the automatic switching circuit of main and auxiliary power supply, with "zero" voltage drop and static current of 20ua

又一百万量子比特!以色列光量子初创公司完成1500万美元融资

密码学系列之:在线证书状态协议OCSP详解

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

杰理之播内置 flash 提示音控制播放暂停【篇】

Uniapp adaptation problem

美国空军研究实验室《探索深度学习系统的脆弱性和稳健性》2022年最新85页技术报告

函数重入、函数重载、函数重写自己理解

Not All Points Are Equal Learning Highly Efficient Point-based Detectors for 3D LiDAR Point
随机推荐
腾讯云原生数据库TDSQL-C入选信通院《云原生产品目录》
[colmap] 3D reconstruction with known camera pose
树莓派设置wifi自动连接
杰理之FM 模式单声道或立体声选择设置【篇】
An error in SQL tuning advisor ora-00600: internal error code, arguments: [kesqsmakebindvalue:obj]
Lost in the lock world of MySQL
mos管實現主副電源自動切換電路,並且“零”壓降,靜態電流20uA
LAB1配置脚本
Matlab Error (Matrix dimensions must agree)
Intelligent static presence detection scheme, 5.8G radar sensing technology, human presence inductive radar application
编译常量、ClassLoader类、系统类加载器深度探析
sshd[12282]: fatal: matching cipher is not supported: aes256- [email protected] [preauth]
Hazel engine learning (V)
Jerry's question about DAC output power [chapter]
IDEA重启后无法创建Servlet文件的解决方案
杰理之在非蓝牙模式下,手机连接蓝牙不要跳回蓝牙模式处理方法【篇】
Decoration design enterprise website management system source code (including mobile source code)
QT Bluetooth: qbluetooth DeviceInfo
尚硅谷JVM-第一章 类加载子系统
源代码保密的意义和措施