当前位置:网站首页>The fifth Bureau, akali teaching Bureau
The fifth Bureau, akali teaching Bureau
2022-07-21 20:32:00 【Cold hands a】
// Write a question that you can calculate the total scores of Chinese and Mathematics for your third grade brother Code
#include<stdio.h>
int main()
{
int chinese = 0;
int math = 0;
scanf_s("%d %d", &chinese, &math);
int sum = chinese + math;
printf("sum = %d\n", sum);
return 0;
}
/ If you want to calculate the total score of Chinese and Mathematics for the whole class ? List the repeated codes , That's a lot low ah And that's where it comes in function
#include<stdio.h>
int ADD(int chinese, int math) //int Function type ;ADD Function name ;( Function parameter 1, Function parameter 2)
{
return chinese + math;//return Function return value type
}
// Like what to eat Pull what meat ( Acid food ) Eat into your stomach Excretion is acidic
int main()
{
int chinese = 0;
int math = 0;
scanf_s("%d %d", &chinese, &math);
int sum =ADD(chinese, math);
printf("sum = %d\n", sum);
return 0;
}
function :
/*----------------------------------------------------------------
As mentioned earlier One dimensional array , It can be understood as X Axis ; Two dimensional array It is the X-Y Axis ( Plane coordinate system )
*/
#include<stdio.h>
int main()
{
int group[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };// One dimensional array
int group_two[][3] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };// Two dimensional array Equivalent to three rows and three columns
// Visit a one-dimensional array
printf("%d\n", group[0]);
printf("%d\n", group[1]);
printf("%d\n", group[2]);
// Access 2D array
printf("%d\n", group_two[2][0]);// visit [][] You have to write the subscript
return 0;
}
Execution results :
// Take one-dimensional array for example , The subscript is from 0 At the beginning , You want to get 1, Is access group[0],o Subscript at , And so on
Two dimensional array writing :
Two dimensional array subscript :
#include<stdio.h>
int main()
{
int group[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };// One dimensional array
int group_two[][3] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };// Two dimensional array Equivalent to three rows and three columns
Visit a one-dimensional array
//printf("%d\n", group[0]);
//printf("%d\n", group[1]);
//printf("%d\n", group[2]);
// Access one-dimensional array in a circular way The same goes for two-dimensional arrays
int frequency = 0;
while (frequency < 9) {
printf("%d\n", group[frequency]);
frequency++;
}
// Calculate the total size of the array Calculate the size of an element
printf("group = %d\n", sizeof(group));//9 Elements , One int Occupy 4 Bytes 4*9=36
printf("group[0]=%d\n", sizeof(group[0]));//4
// Calculate the total size of the array / Calculate the size of an element = Element number
int number = sizeof(group) / sizeof(group[0]);
printf("number = %d\n", number);
Access 2D array
//printf("%d\n", group_two[2][0]);// visit [][] You have to write the subscript
// Take one-dimensional array for example , The subscript is from 0 At the beginning , You want to get 1, Is access group[0],o Subscript at , And so on
return 0;
}
Second half : The pointer + Structure To rush !!!
边栏推荐
猜你喜欢
随机推荐
1020 moon cake
碎碎念 碎碎念 下 原稿
2020常州市程序设计小能手真题及题解
如何免费在本地播放flv格式的视频
Hetai 32 onenet WiFi module - Hetai MCU data cloud through mqtt protocol (I)
1019 digital black hole
Record some little cheese about writing the program ~ [continue to be more ~]
Namespace namespace
第五局 阿卡丽教学局 下 数据分析
Acwing 175 circuit maintenance
无法从“boost::shared_ptr<pcl::RangeImage>”转换为“const std::shared_ptr<const pcl::PointCloud<pcl::PointWit
(剑指off版)旋转数组求最小值(通俗易懂)
受控组件和非受控组件的区别
无人机的微分平坦性详细推导
scanf 详解 - 你所不知道的scanf用法
再见了,各位(虽然没人会注意到)
CSDN2022总排名前十统计
17.【setw()函数的运用】
如何使用迭代最近点ICP
第五局 阿卡丽教学局 上