当前位置:网站首页>Input and output of C language pointer to two-dimensional array
Input and output of C language pointer to two-dimensional array
2022-07-07 01:54:00 【The universe is hidden in the book】
C Language use pointer to enter and input grades
// Pointer to array as function parameter
/* The example title comes from tanhaoqiang C Language programming Fifth Edition 251 page There is a class , There are three students , Learn four courses each , Calculate the total average score and the total score of a designated student And can independently judge the grades of students who fail in various subjects */
#include <stdio.h>
int main()
{
void average(float * p,int n );
void search(float(*p)[4],int n);
void score_input(float score[3][4]);
void pointer_score_input(float * p,int n);
float score[3][4];
//score_input(score);// Input of array version
pointer_score_input(score,12);// Pointer input
average(*score,12);
search(score,3);
return 0;
}
// Define the average function
void average(float * p,int n )
{
float sum=0,aver;
float * p_end;
for(p_end=p;p<p_end+n;p++)
sum=sum+(*p);
aver=sum/n;
printf(" The average score is :%f\n",aver);
}
// Define the function of finding grades
void search(float(*p)[4],int n) // there (*p)[4] Is pointing to having 4 A pointer to a one-dimensional array
{
int i,j,m,flag=0;
//printf(" The students with this grade are %d classmate \n",n);
for(j=0;j<n;j++)
{
for (i=0;i<4;i++)
if(*(*(p+j)+i)<60)
flag=1;
if(flag==1)
{
printf(" The students who fail are %d, His grades in all subjects are \n",j+1);
flag=0;
printf("\n");
for (m=0;m<4;m++)
printf(" %f",*(*(p+j)+m));// The front one *(p+n) It refers to the number of students , Back i It refers to the grade of the student's grade
}
printf("\n");
}
printf("\n");
}
// Score input function
void score_input(float score[3][4])
{
int i,j;
printf(" Please enter the student's grade ");
for(i=0;i<3;i++)
for(j=0;j<4;j++)
scanf(" %f",&score[i][j]);
printf(" Input complete \n");
}
// Pointer version input grade function
void pointer_score_input(float * p,int n)
{
float *score_pointer;
score_pointer=p+n;// Send the address to score_pointer The pointer
printf(" Please enter the student's grade \n");
for(;p<score_pointer;p++)// At this time P The address pointed to by the pointer is scored The first address
scanf("%f",p); // Write data to the specified address
printf(" Input completed \n");
}
边栏推荐
- Let's see how to realize BP neural network in Matlab toolbox
- Domestic images of various languages, software and systems. It is enough to collect this warehouse: Thanks mirror
- How can I code for 8 hours without getting tired.
- swiper组件中使用video导致全屏错位
- AcWing 344. 观光之旅题解(floyd求无向图的最小环问题)
- PartyDAO如何在1年内把一篇推文变成了2亿美金的产品DAO
- AcWing 1142. Busy urban problem solving (minimum spanning tree)
- 2022/0524/bookstrap
- Appium自动化测试基础 — uiautomatorviewer定位工具
- 修改px4飞控的系统时间
猜你喜欢

Can't you understand the code of linked list in C language? An article allows you to grasp the secondary pointer and deeply understand the various forms of parameter passing in the function parameter

2022/0524/bookstrap

@Before, @after, @around, @afterreturning execution sequence

Baidu flying general BMN timing action positioning framework | data preparation and training guide (Part 2)

Gin introduction practice

JVM memory model

Make DIY welding smoke extractor with lighting

Analyze "C language" [advanced] paid knowledge [End]

Blue Bridge Cup 2022 13th provincial competition real topic - block painting

2022/0524/bookstrap
随机推荐
CISP-PTE实操练习讲解(二)
Basic introduction and use of dvajs
AcWing 1148. Secret milk transportation problem solution (minimum spanning tree)
ROS学习(二十)机器人SLAM功能包——rgbdslam的安装与测试
js如何快速创建一个长度为 n 的数组
AcWing 361. Sightseeing cow problem solution (SPFA seeking positive ring)
ROS learning (23) action communication mechanism
First experience of JSON learning - the third-party jar package realizes bean, list and map to create JSON format
猫猫回收站
Box stretch and pull (left-right mode)
Today's question -2022/7/4 modify string reference type variables in lambda body
AcWing 346. Solution to the problem of water splashing festival in the corridor (deduction formula, minimum spanning tree)
AcWing 344. Solution to the problem of sightseeing tour (Floyd finding the minimum ring of undirected graph)
Modify the system time of Px4 flight control
Set WordPress pseudo static connection (no pagoda)
刨析《C语言》【进阶】付费知识【二】
编译命令行终端 swift
swiper组件中使用video导致全屏错位
图片打水印 缩放 和一个输入流的转换
ROS学习(26)动态参数配置