当前位置:网站首页>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 346. 走廊泼水节 题解(推公式、最小生成树)
- The difference between Tansig and logsig. Why does BP like to use Tansig
- 刨析《C语言》【进阶】付费知识【二】
- 454-百度面经1
- Shortcut keys commonly used in idea
- Scenario practice: quickly build wordpress blog system based on function calculation
- IDEA常用的快捷键
- 微服务架构介绍
- Compile command line terminal swift
- 【唯一】的“万字配图“ | 讲透【链式存储结构】是什么?
猜你喜欢
Appium自动化测试基础 — uiautomatorviewer定位工具
AcWing 1148. Secret milk transportation problem solution (minimum spanning tree)
盒子拉伸拉扯(左右模式)
CISP-PTE之命令注入篇
LeetCode. Sword finger offer 62 The last remaining number in the circle
Analyze "C language" [advanced] paid knowledge [i]
mongodb查看表是否导入成功
Yiwen takes you into [memory leak]
Ros Learning (23) Action Communication Mechanism
鼠标右键 自定义
随机推荐
对C语言数组的再认识
Google released a security update to fix 0 days that have been used in chrome
WCF Foundation
AcWing 344. 观光之旅题解(floyd求无向图的最小环问题)
Set WordPress pseudo static connection (no pagoda)
盒子拉伸拉扯(左右模式)
golang 基础 —— 数据类型
mysqlbackup 还原特定的表
ROS learning (23) action communication mechanism
BigDecimal 的正确使用方式
Yiwen takes you into [memory leak]
According to the analysis of the Internet industry in 2022, how to choose a suitable position?
DS-5/RVDS4.0变量初始化错误
设置Wordpress伪静态连接(无宝塔)
AcWing 1148. 秘密的牛奶运输 题解(最小生成树)
Appium自动化测试基础 — uiautomatorviewer定位工具
C language instance_ three
Hutool post requests to set the body parameter to JSON data
POJ 3177 redundant paths POJ 3352 road construction (dual connection)
736. LISP syntax parsing: DFS simulation questions