当前位置:网站首页>[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;
}边栏推荐
- 从0开始创建小程序
- sshd[12282]: fatal: matching cipher is not supported: aes256- [email protected] [preauth]
- Lingyun going to sea | yidiantianxia & Huawei cloud: promoting the globalization of Chinese e-commerce enterprise brands
- How does C language (string) delete a specified character in a string?
- Jerry's phonebook acquisition [chapter]
- The whole process of knowledge map construction
- Leetcode-02 (linked list question)
- QT Bluetooth: qbluetooth DeviceInfo
- mos管实现主副电源自动切换电路,并且“零”压降,静态电流20uA
- Jerry's transmitter crashed after the receiver shut down [chapter]
猜你喜欢

Flink task exit process and failover mechanism

Significance and measures of source code confidentiality

Experience design details

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

uniapp适配问题

Form validation of uniapp

你知道电子招标最突出的5大好处有哪些吗?

Leetcode-02 (linked list question)

HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother

mos管实现主副电源自动切换电路,并且“零”压降,静态电流20uA
随机推荐
c语言(字符串)如何把字符串中某个指定的字符删除?
Do you know the five most prominent advantages of E-bidding?
[cpk-ra6m4 development board environment construction based on RT thread studio]
凌云出海记 | 易点天下&华为云:推动中国电商企业品牌全球化
Mathematical induction and recursion
杰理之开 BLE 退出蓝牙模式卡机问题【篇】
netperf 而网络性能测量
tensorboard的使用
美国空军研究实验室《探索深度学习系统的脆弱性和稳健性》2022年最新85页技术报告
sshd[12282]: fatal: matching cipher is not supported: aes256- [email protected] [preauth]
SSL证书错误怎么办?浏览器常见SSL证书报错解决办法
The solution of unable to create servlet file after idea restart
2022年信息安全工程师考试大纲
Cocos2d-x Box2D物理引擎编译设置
腾讯云原生数据库TDSQL-C入选信通院《云原生产品目录》
Intelligent static presence detection scheme, 5.8G radar sensing technology, human presence inductive radar application
Data analysis from the perspective of control theory
Codeforces round 264 (Div. 2) C gargari and Bishop [violence]
Install torch 0.4.1
Jerry's phonebook acquisition [chapter]