MODE ——计算了 任意多个数字的平均值(知识点:for的循环)

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_42167759/article/details/83652425

问题描述:

输入浮点数值 判断是否继续输入 输出N时候 退出for循环 计算出来 输入所有数字的平均值

运行结果:

[root@J01051386 C]# ./a.out 

This program calculates the average of any number of values.
Enter a value:1
Do you want to enter another value?(Y or N):y

Enter a value:2
Do you want to enter another value?(Y or N):y

Enter a value:3
Do you want to enter another value?(Y or N):n

The average is 2.00

代码部分:

#include <stdio.h>
#include <ctype.h>
int main(void)
{
	char answer = 'N';
	double total = 0.0;
	double value = 0.0;
	unsigned int count = 0;
	
	printf("\nThis program calculates the average of any number of values.");
//for 循环中的break 的使用	
	for (;;)
	{	
		printf("\nEnter a value:");
		scanf(" %lf",&value);
		total += value;
		++count;
		
		printf("Do you want to enter another value?(Y or N):");
		scanf(" %c",&answer);
		if(tolower(answer) == 'n')
			break;
	}	
	printf("\nThe average is %.2lf\n",total/count);
	return 0;
}

 

展开阅读全文

利率改变,无法计算了????

03-04

![图片说明](https://img-ask.csdn.net/upload/201603/04/1457063082_596440.png)nn如图片所说的一样 nn我吧js传上来吧 nn```n /*nid:n 平均 show 税前 input1 基数 input2n 合计:n 个人 input3 单位 input4n 个人:n 养老 input5 医疗 input7 失业 input9 工商 input11 生育input13n 单位:n 养老 input6 医疗 input8 失业 input10 工商 input12 生育 input14n*/nn $(document).ready(function() n //显示当前日期n var d = new Date();n var s2 = d.getFullYear() + "-" + (d.getMonth()+1) + "-" + d.getDay();n $('#EntTime30').val(s2);nn // 地区变动 平均工资变动n $('#area').change(function()n n $('#show').val($(this).find("option:selected").val()) ;n nn );n //以税前收入判断社保基数n $("#input1").change(function()n input1 = parseFloat($(this).val())||0;n n n if(input1*40/100 <= 2000 )n al = 2000;n $("#input2").val(al);n else if( input1*300/100 >= 20838)n al = 20838;n $("#input2").val(al);n elsen al = input1 ;n $("#input2").val(al);n nn );n //计算n $("#input1,#show,#input5,input6,input7,input8,input9,input10,input11,input12,input13,input14").change(function()n input1 = parseFloat($("#input1").val())||0;n show = parseFloat($("#show").val())||0;n input5 = parseFloat($("#input5").val())||0;n input6 = parseFloat($("#input6").val())||0;n input7 = parseFloat($("#input7").val())||0;n input8 = parseFloat($("#input8").val())||0;n input9 = parseFloat($("#input9").val())||0;n input10 = parseFloat($("#input10").val())||0;n input11 = parseFloat($("#input11").val())||0;n input12 = parseFloat($("#input12").val())||0;n input13 = parseFloat($("#input13").val())||0;n input14 = parseFloat($("#input14").val())||0;n n //养老保险n if(input1<=show*40/100) n //个人n sl = show*40/100*input5/100; n dl = show*40/100*input6/100;n n else if(input1 > show*300/100)n sl = show*300/100*input5/100;n n dl = show*300/100*input6/100;n n elsen dl = input1*input6/100;n n sl = input1*input5/100;n n n n //医疗保险n if( input1 <= show*60/100)n //个人n fl = show*60/100*input7/100;n //单位n gl = show*60/100*input8/100;n n else if( input1 > show*300/100)n fl = show*300/100*input7/100;n n gl = show*300/100*input8/100;n elsen fl = input1*input7/100;n n gl = input1*input8/100;n n n //失业保险n if( input1 <= show*40/100)n //个人n hl = show*40/100*input9/100;n //单位n jl = show*40/100*input10/100;n n else if( input1 > show*300/100)n hl = show*300/100*input9/100;n n jl = show*300/100*input10/100;n elsen hl = input1*input9/100;n n jl = input1*input10/100;n n n //工伤保险n if( input1 <= show*60/100)n //个人n kl = show*60/100*input11/100;n //单位n ll = show*60/100*input12/100;n n else if( input1 > show*300/100)n kl = show*300/100*input11/100;n n ll = show*300/100*input12/100;n elsen kl = input1*input11/100;n n ll = input1*input12/100;n n n n //生育保险n if( input1 <= show*60/100)n //个人n ql = show*60/100*input13/100;n //单位n wl = show*60/100*input14/100;n n else if( input1 > show*300/100)n ql = show*300/100*input13/100;n n wl = show*300/100*input14/100;n elsen ql = input1*input13/100;n n wl = input1*input14/100;n n n n n n //总计n //个人n var input3 = '';n input3 = sl+fl+hl+kl+ql;n $('#input3').val(input3.toFixed(2));n n var input4 = '';n input4 = dl+gl+jl+ll+wl;n $('#input4').val(input4.toFixed(2));n );n n); nn```nnn$("#input1,#show,#input5,input6,input7,input8,input9,input10,input11,input12,input13,input14").change(function()nn是因为这个原因吗 nn 问答

多个区站的平均值

12-02

表:Meso_2008.dbo.LN_200812rnID 区站号 插入时间 瞬时风速 瞬时风向 温度rn1 L6509 2008-12-2 14:41:00 3 141 2.2rn2 L6509 2008-12-2 14:40:00 2 131 3.1 rn3 L6509 2008-12-2 14:39:00 5 124 4.2rn4 L6510 2008-12-2 14:41:00 3 141 2.2rn5 L6510 2008-12-2 14:40:00 2 131 3.1 rn6 L6510 2008-12-2 14:39:00 5 124 4.2rnrn------------------------------------------------------------------------rn表:dbo.tabTimeDatarnrnID 区站号 插入时间 瞬时风速 瞬时风向 温度rn1 L6509 2008-12-2 15:00:00 3.3 132 3.2rn2 L6510 2008-12-2 15:00:00 3.3 132 3.2rnrn-------------------------------------------------------------------------rnALTER PROCEDURE [dbo].[selcetLNFXQXJ] rn-- Add the parameters for the stored procedure here rn@p1 int = 0 rnAS rnBEGIN rn-- SET NOCOUNT ON added to prevent extra result sets from rn-- interfering with SELECT statements. rnSET NOCOUNT ON; rnrn -- Insert statements for procedure here rnrn INSERT dbo.tabTimeData( 区站号, 入库时间, 通信方式, 日期时间, 电源状态, 瞬时风速, 瞬时风向, 二分风速, 二分风向, 十分风速, 十分风向, 极大风速, 极大风向, 极大风速对应时间, 最大风速, 最大风向, 最大风速对应时间, 分钟雨量, 一小时雨量, 十分钟最大雨强, 最大雨强出现时间, 空气温度, 最高气温, 最高气温出现时间, 最低气温, 最低气温出现时间, 相对湿度, 最小湿度, 最小湿度出现时间, 本站气压, 最高气压, 最高气压出现时间, 最低气压, 最低气压出现时间) rn select rn cast(区站号 as char(8)), rn cast(插入时间 as datetime), rn 'G', rn cast(观测时间 as datetime), rn cast(电池电压 as char(8)), rn cast(瞬时风速 as int), rn cast(瞬时风向 as int), rn cast(二分钟平均风速 as int), rn cast(二分钟平均风向 as int), rn cast(十分钟平均风速 as int), rn cast(十分钟平均风向 as int), rn cast(极大风速 as int), rn cast(极大风速的风向 as int), rn cast(极大风速出现时间 as char(10)), rn cast(最大风速 as int), rn cast(最大风速的风向 as int), rn cast(最大风速出现时间 as char(10)), rn cast(小时每分钟雨量 as char(120)), rn cast(小时雨量 as int), rn NULL, rn NULL, rn cast(气温 as int), rn cast(最高气温 as int), rn cast(最高气温出现时间 as char(10)), rn cast(最低气温 as int), rn cast(最低气温出现时间 as char(10)), rn cast(相对湿度 as int), rn cast(最小相对湿度 as int), rn cast(最小相对湿度出现时间 as char(10)), rn cast(本站气压 as int), rn cast(最高本站气压 as int), rn cast(最高本站气压出现时间 as char(10)), rn cast(最低本站气压 as int), rn cast(最低本站气压出现时间 as char(10))rn from openrowset('SQLOLEDB','FXQXJ';'sa';'sa',Meso_2008.dbo.LN_200812) rn where 区站号 = 'l6509' and datediff(hh,插入时间,getdate())=0rnrnEND rn---------------------------------------------------------rn表:Meso_2008.dbo.LN_200812中的数据是每分钟生成一条的,我想要每隔小时计算一次,生成这个小时的平均数据。另外我下面写的是查询一个区站的语句,多个区站怎么处理啊?第一个表里一共18个区站,几万条数据呢,怎么办啊,鼓捣一天了,也没算出来。大伙多费心了rn------------------------------------------------------------rnrnrnrnrn 论坛

没有更多推荐了,返回首页