p277 第十章 数组和指针
2016-02-14 17:11
267 查看
//flc.c--有趣的常量
#include<stdio.h>
#define COLS 4
int sum2d (int ar[][COLS], int rows);
int sum (int ar[],int n);
int main (void)
{
int tota11, tota12, tota13;
int *pt1;
int (*pt2)[COLS];
pt1=(int [2]) {10,20};
pt2=(int [2][COLS]) {{1,2,3,-9},{4,5,6,-8}};
tota11=sum(pt1,2);
tota12=sum2d(pt2,2);
tota13=sum((int []) {4,4,4,5,5,5},6);
printf ("tota11=%d\n",tota11);
printf ("tota12=%d\n",tota12);
printf ("tota13=%d\n",tota13);
return 0;
}
int sum (int ar[],int n)
{
int i;
int tota1=0;
for (i=0;i<n;i++)
tota1 += ar[i];
return tota1;
}
int sum2d (int ar[ ][COLS], int rows)
{
int r;
int c;
int tot=0;
for (r=0;r<rows;r++)
for (c=0;c<COLS;c++)
tot += ar[r][c];
return tot;
}
#include<stdio.h>
#define COLS 4
int sum2d (int ar[][COLS], int rows);
int sum (int ar[],int n);
int main (void)
{
int tota11, tota12, tota13;
int *pt1;
int (*pt2)[COLS];
pt1=(int [2]) {10,20};
pt2=(int [2][COLS]) {{1,2,3,-9},{4,5,6,-8}};
tota11=sum(pt1,2);
tota12=sum2d(pt2,2);
tota13=sum((int []) {4,4,4,5,5,5},6);
printf ("tota11=%d\n",tota11);
printf ("tota12=%d\n",tota12);
printf ("tota13=%d\n",tota13);
return 0;
}
int sum (int ar[],int n)
{
int i;
int tota1=0;
for (i=0;i<n;i++)
tota1 += ar[i];
return tota1;
}
int sum2d (int ar[ ][COLS], int rows)
{
int r;
int c;
int tot=0;
for (r=0;r<rows;r++)
for (c=0;c<COLS;c++)
tot += ar[r][c];
return tot;
}
相关文章推荐
- 【JS学习笔记】内置对象
- JVM 内存基础概念之 Java 堆
- 8VC Venture Cup 2016 - Elimination Round A. Robot Sequence
- 【HDU 2203】亲和串
- 学习MongoDB(三) Add an Arbiter to Replica Set 集群中加入仲裁节点
- Visual Studio 2008 可扩展性开发(六):操作Solution Explorer
- jquery ajax No 'Access-Control-Allow-Origin' header is present on the requested resource
- nginx referer限制
- Python语言实践分析 -- 默认参数
- Visual Studio 2008 可扩展性开发(五):操作Solution、Project和ProjectItem
- 【JS学习笔记】基本包装类型
- 谈谈自己处理拍照剪裁的一些经验和遇到的问题
- 【bzoj3171】[Tjoi2013]循环格 (费用流)
- Zabbix高可用,实现zabbix的无缝切换,无故障时间
- redis练习手册<十一>set主要操作函数小结
- JavaWeb学习总结(二)——Tomcat服务器学习和使用(一)
- 优化 Android 线程和后台任务开发
- unity, ugui button 禁止重复点击
- MySQL Workbench 6.3 CE 不显示MySql、infomation_schema等数据库
- 用Azure CLI批量上传文件