• 统计数据

简单多数据输出
源代码:

#include<stdio.h>
#define TE 100000000
int main()
{
	int x,n=0,kase=0,min,max;
	while(scanf("%d",&n) == 1 && n) //判断输入是否为0
	{
		min=TE;max=-TE; //定义的足够大(小)才能保证不影响输入值
		int  s= 0;
		for(int i=0;i<n;i++)
		{
			
			scanf("%d",&x);
			s+=x;
			if(x<min) min = x;
			if(x>max) max = x;
		} 
		if(kase) printf("\n"); //改变kase换行
		printf("Case %d:%d %d %.3f\n",++kase,min,max,(double)s/n);
	}
	return 0;
}

简单多数据输出

  • 分数化小数

简单多数据输出

#include<stdio.h>
int main()
{
	int c,m=0;
	double a,b;
	while(scanf("%lf",&a) == 1 && a && scanf("%lf",&b)==1 && b && scanf("%d",&c)==1 && c)    //保证都不为0,循环一直进行
		printf("Case %d: %.*lf\n",++m,c,a/b);  //.*lf可以设置变量精度
	return 0;
}

简单多数据输出

相关文章:

  • 2022-02-22
  • 2022-01-18
  • 2021-09-12
  • 2022-12-23
  • 2021-08-13
  • 2022-12-23
  • 2021-09-12
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2021-05-13
  • 2022-12-23
  • 2021-12-09
  • 2021-09-01
相关资源
相似解决方案