当前位置:网站首页>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");
}
边栏推荐
- AcWing 344. Solution to the problem of sightseeing tour (Floyd finding the minimum ring of undirected graph)
- How can I code for 8 hours without getting tired.
- Shell script quickly counts the number of lines of project code
- JS es5 peut également créer des constantes?
- Batch delete data in SQL - set in entity
- MySQL's most basic select statement
- AcWing 1142. Busy urban problem solving (minimum spanning tree)
- Add PDF Title floating window
- ROS learning (22) TF transformation
- json学习初体验–第三者jar包实现bean、List、map创json格式
猜你喜欢

How can I code for 8 hours without getting tired.

Appium foundation - appium inspector positioning tool (I)

Gin 入门实战

454 Baidu Mianjing 1

AcWing 345. 牛站 题解(floyd的性质、倍增)

蓝桥杯2022年第十三届省赛真题-积木画

AcWing 361. 观光奶牛 题解(spfa求正环)

ROS学习(十九)机器人SLAM功能包——cartographer

js如何快速创建一个长度为 n 的数组

Baidu flying general BMN timing action positioning framework | data preparation and training guide (Part 1)
随机推荐
MySQL最基本的SELECT(查询)语句
Telnet,SSH1,SSH2,Telnet/SSL,Rlogin,Serial,TAPI,RAW
百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (上)
Let's see how to realize BP neural network in Matlab toolbox
Long press the button to execute the function
猫猫回收站
ROS学习(二十)机器人SLAM功能包——rgbdslam的安装与测试
2022/0524/bookstrap
POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)
ROS学习(25)rviz plugin插件
Compile command line terminal swift
字符串转成日期对象
C语言关于链表的代码看不懂?一篇文章让你拿捏二级指针并深入理解函数参数列表中传参的多种形式
Gin 入门实战
dvajs的基础介绍及使用
POJ 3177 redundant paths POJ 3352 road construction (dual connection)
糊涂工具类(hutool)post请求设置body参数为json数据
JS Es5 can also create constants?
IDEA常用的快捷键
LeetCode. Sword finger offer 62 The last remaining number in the circle