当前位置:网站首页>C language ----- array
C language ----- array
2022-07-20 22:49:00 【Classmate Zheng should work hard】
For reference only 、 For reference only 、 For reference only ( Tidy up your freshman C Exercises for each chapter of the language 、 No problem 、 Only the program )
List of articles
1 、 Training name
Practical training 7: Array
2 、 Training objectives and requirements
The experiment purpose :
1、 Master one-dimensional array , Two dimensional array , Definition of character array 、 assignment 、 Input 、 Output method
2 、 Master one-dimensional array , Two dimensional array , Use of character arrays
3 、 Master the algorithms related to arrays through computer practice
3 、 Source code and running screenshot
【6-6】
(1)
#include<stdio.h>
int main (){
int i=0, j,a[10],temp;
printf(" Please enter ten integers :\n");
for(int i=0;i<10;i++){
scanf("%d ",&a[i]);// Get the integer from the keyboard
}
// Bubble sort
for(int i=0;i<9;i++){
for(int j=0;j<10-i;j++){
if(a[j]>a[j+1])
{
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}
}
for(int i=0;i<10;i++){
printf("%d\n",a[i]);
}
return 0;
}
(2)、
#include<stdio.h>
int main (){
int a1,b2,c3,d4,e5,f6,g7,h8,i9,g10,k11,l12,sum=0;
a1=4;// January
printf("1 Monthly output :%d\n",a1);
b2=(a1-1)*2;
printf("2 Monthly output :%d\n",b2);
c3= (b2-1)*2;
printf("3 Monthly output :%d\n",c3);
d4=(c3-1)*2;
printf("4 Monthly output :%d\n",d4);
e5= (d4-1)*2;
printf("5 Monthly output :%d\n",e5);
f6=(e5-1)*2;
printf("6 Monthly output :%d\n",f6);
g7= (f6-1)*2;
printf("7 Monthly output :%d\n",g7);
h8=(g7-1)*2;
printf("8 Monthly output :%d\n",h8);
i9=(h8-1)*2;
printf("9 Monthly output :%d\n",i9);
g10=(i9-1)*2;
printf("10 Monthly output :%d\n",g10);
k11=(g10-1)*2;
printf("11 Monthly output :%d\n",k11);
l12=(k11-1)*2;
printf("12 Monthly output :%d\n",l12);
sum=a1+b2+c3+d4+e5+f6+g7+h8+i9+g10+k11+l12;
printf(" Total output :%d\n",sum);
return 0;
}
(4)、
#define N 50
#include<stdio.h>
int main (){
int i,n ,a,count;
for(n=1;n<N;n+=2){
for(i=0;i<n;i++){
count++;
if(count==40)
printf(" The fortieth data :%d\n",n);
}
}
return 0;
}
(5)、
#include<stdio.h>
int main (){
int i,j, b;
int sum=0,f[3][4];
// Keyboard input two-dimensional array
for(i=0;i<3;i++){
printf(" Please enter four data :\n");
for(j=0;j<4;j++){
scanf("%d",&f[i][j]);
printf("\n");
}
}
for(i=0;i<3;i++){
sum+=f[i][1];
}
printf(" The sum of the second column is %d",sum);
return 0;
}
(6)、
#include<stdio.h>
int main (){
int i,j, b;
int sum=0,sum1=0,sum2=0,sum3=0,sum4=0,f[4][5];
// Keyboard input two-dimensional array
for(i=0;i<4;i++){
printf(" The first %d Line five elements :\n",i+1);
for(j=0;j<5;j++){
scanf("%d",&f[i][j]);
}
}
for(j=0;j<5;j++){
sum1=sum1+f[0][j];
}
printf(" The first line and :%d\n",sum1);
for(j=0;j<5;j++){
sum2+=f[3][j];
}
printf(" The fourth line and :%d\n",sum2);
for(i=1;i<3;i++){
sum3+=f[i][0];
}
printf(" The first column and :%d\n",sum3);
for(i=1;i<3;i++){
sum4+=f[i][4];
}
printf(" The fifth column and :%d\n",sum4);
sum=sum1+sum2+sum3+sum4;
printf(" Edge and yes %d",sum);
return 0;
}
(7)、
#include<stdio.h>
int main (){
int t,i,j;
int f[3][4];
int a,b,max;
// Keyboard input two-dimensional array
for(i=0;i<3;i++){
printf(" The first %d Line four elements :\n",i+1);
for(j=0;j<4;j++){
scanf("%d",&f[i][j]);
}
}
printf("\n");
max=f[0][0];
for(i=0;i<3;i++){
for(j=0;j<4;j++){
printf("%3d",f[i][j]);
if(f[i][j]>max){
max=f[i][j];
a=i;
b=j;
}
}printf("\n");
}
printf("%d,%d\n",a,b);
printf(" The maximum value of the output array :%d\n",max);
return 0;
}
(8)、
#include<stdio.h>
int main (){
int t,i,j;
int a[3][3];
int b[3][3];
// Keyboard input two-dimensional array
for(i=0;i<3;i++){
printf(" The first %d Line three elements :\n",i+1);
for(j=0;j<3;j++){
scanf("%d",&a[i][j]);
}
}
printf(" Array a:\n");
for(i=0;i<3;i++){
for(j=0;j<3;j++){
printf("%-4d",a[i][j]);
}
printf("\n");
}
printf("\n");
printf("\n");
for(i=0;i<3;i++){
printf(" The first %d Line three elements :\n",i+1);
for(j=0;j<3;j++){
scanf("%d",&b[i][j]);
}
}
printf(" Array b:\n");
for(i=0;i<3;i++){
for(j=0;j<3;j++){
printf("%-4d",b[i][j]);
}
printf("\n");
}
printf(" Array a And an array b The result of the addition is in the array c Show in \n");
for(i=0;i<3;i++){
for(j=0;j<3;j++){
printf("%-4d",a[i][j]+b[i][j]);
} printf("\n");
}
return 0;
}
4、 Summary
Through this exercise, I can skillfully master the structure of arrays and some simple applications , The implementation of one-dimensional array is relatively simple 、 Two dimensional arrays are relatively complex . When dynamically outputting a two-dimensional array, you need to use a two-layer loop to assign values to the array . The output and input of two-dimensional array mainly involve two layers for Loop to output and input the values of each row and column in the array . Using arrays can achieve a simple sorting method , The principle of bubble sorting is to exchange two adjacent numbers through two-layer circulation , Keep comparing, and finally realize a sequential number table .
边栏推荐
- 1054 The Dominant Color
- Unity_同个材质多个颜色内存优化——使用MaterialPropertyBlock
- mysql增删查改
- 中国式IT运维,趟出自己的“长期主义”河流
- Enrollment brochure for system integration project management engineer certification in the second half of 2022
- 2022年北京产品经理认证招生简章(NPDP)
- [go language] (I) environment building and understanding vscode tools
- 众享比特成立八周年暨众享链网一周年庆典,正式发布新世界宣言
- FileUploadBase$SizeLimitExceededException
- IEC104 simulator tutorial
猜你喜欢
我的Notepad++插件推荐
英国高温:两个机场跑道被烤坏 多条铁路限速保安全
C语言文件操作
MySQL deadlock, lock timeout, slow SQL summary
从wolai转移到Notion
在电脑主机(MainFrame)中只需要按下主机的开机按钮(on()),即可调用其它硬件设备和软件的启动方法,如内存(Memory)的自检(check())、CPU的运行(run())、硬盘(Hard
M matlab performance simulation of optical fiber communication system based on Fiber Bragg grating sensor network connected to GPON, including decoding, unpacking, demultiplexing, rate recovery, frami
m基于光纤光栅传感网接入GPON的光纤通信系统matlab性能仿真,包括解码,解封装,分接,码率恢复,解帧,拆包,译码
m基于matlab的IEEE802.15.4家庭网络高效节能的有效接入方法
How to publish and subscribe messages with redis? What is the implementation principle?
随机推荐
Huawei wireless device roaming configures non fast roaming between APs of the same service VLAN
Typescript正则之前后断言与具名组和解构
Unity_同个材质多个颜色内存优化——使用MaterialPropertyBlock
Flink 的sink表插入到mysql表后,时间减少了8小时,谁知道 这是什么问题?
GDAL图像重采样
在电脑主机(MainFrame)中只需要按下主机的开机按钮(on()),即可调用其它硬件设备和软件的启动方法,如内存(Memory)的自检(check())、CPU的运行(run())、硬盘(Hard
Makefile implements compilation time statistics
TIA botu_ Summary of difficulties related to the upgrade and migration of STEP7 version
基于BIO模式下通信项目
Matlab 冰壶仿真游戏安装及教程
Matrikon OPC simulator tutorial
How to publish and subscribe messages with redis? What is the implementation principle?
XML to VOC, VOC to coco, coco to Yolo, coco partition, coco check, Yolo check, coco visualization
明晚19点直播 | 深度剖析:数据湖中的对象存储
The training accuracy is comparable to alphafold2, and the speed is doubled. The helixfold training and reasoning code of the propeller is fully open source
Uniapp uses hbuilder x mode to install uivew plug-in steps
从wolai转移到Notion
面试高并发,凉了(全程高能,赶快收藏)
leetcode:146. LRU最近最少使用 缓存
30 open source software most popular with IT companies