C lang:Array_Multidimensional arrays
时间:2019-11-21
本文章向大家介绍C lang:Array_Multidimensional arrays,主要包括C lang:Array_Multidimensional arrays使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
#include<stdio.h>
#include<windows.h>
#define YEARS 5
#define MONTHS 12
void color(short x);
int main(void)
{
//definition array
const float rain[YEARS][MONTHS] =
{
{1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 0.1, 0.2, 0.3},
{1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 0.1, 0.2, 0.3},
{1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 0.1, 0.2, 0.3},
{1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 0.1, 0.2, 0.3},
{1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 0.1, 0.2, 0.3}
};
const char mon[12][10] = {"January" , "February" , "March" , "April" , "May" , "June" , "July" , "August" , "September" , "October" , "November" , "December"};
int year, month;
int i,w;
float subtot, total, subtotv;
color(5);
printf(" Year Rainfall(inches)\n");
color(4);
for (year = 0, total = 0; year < YEARS; year++) // years cyclic out layer
{
for (month = 0, subtot = 0; month < MONTHS; month++) // month cyclic in layer
{
subtot = subtot + rain[year][month]; // per month count rain
}
total = total + subtot; // five years count rain
printf(" %d%11.2f\n",2016+year,total);
}
color(5);
w =0;
for(i = 0; i < MONTHS; i++)
printf("%13s",mon[i]);
printf("\n");
color(4);
for (month = 0; month < MONTHS; month++) // month cyclic out layer
{
for (year = 0, subtotv = 0; year < YEARS; year++) // years cyclic in layer
{
subtotv = subtotv + rain[year][month]; // sth month years count
}
// printf("%.1f\n",subtotv);
subtotv = subtotv / YEARS; // sth month years average
printf("%13.2f",subtotv);
// printf("%.1f\n---------\n",subtotv);
}
// printf("%.1f",rain[1][0]);
// printf("%.1f\n%.1f\n%.1f\n",subtot, total, subtotv);
color(16);
printf("\n");
printf("\n"); printf("\n"); printf("\n");
system("pause");
return 0;
}
void color(short x)
{
if(x >= 0 && x <= 15)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x);
else
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
}
原文地址:https://www.cnblogs.com/enomothem/p/11906235.html
- Silverlight Telerik控件学习:主题Theme切换
- Silverlight自定义类库实现应用程序缓存
- Silverlight Telerik控件学习:TreeView数据绑定并初始化选中状态、PanelBar的Accordion效果、TabPanel、Frame基本使用
- 这或许是对小白最友好的python入门了吧——4,列表
- 每个人都应该知道的十个机器学习常识
- 重新带你了解React.js
- WebService又一个不爽的地方
- 劲爆!小程序又增新功能!为落地微信智慧零售方案做铺垫!
- 5G光传送网技术
- 突破封闭 Web 系统的技巧之正面冲锋
- 建立本地的Blast数据库
- [biztalk笔记]-1.Hello World!
- 人工智能对政府意味着什么
- 利用Linq对集合元素合并、去重复处理
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法