45mm=_____nm 2.5h=______min=______s 1s=______μs
来源:学生作业帮助网 编辑:六六作业网 时间:2024/08/15 12:53:52
45mm=_____nm 2.5h=______min=______s 1s=______μs
45mm=_____nm 2.5h=______min=______s 1s=______μs
45mm=_____nm 2.5h=______min=______s 1s=______μs
在catm3的基础上,修改了下:
#include<stdio.h>
#include<stdlib.h>
#include <time.h>
//fill and print random numbers
void fillNum(int* const buf,int const count)
{
srand((unsigned)time(NULL));
printf("-----------------------------\n");
for(int i=0;i<count;i++)
{
buf[i]=rand();
printf("Random Number %d:%d\n",i,buf[i]);
}
printf("-----------------------------\n");
}
//find the max and the min number,also calculate the sum and tne average
void calcMaxMinSum(int* const buf,int const count,int * const pMin,
int * const pMax,int * const pSum,double * const pAvg)
{
pMin[0]=pMax[0]=buf[0];
pSum[0]=0;
for(int i=0;i<count;i++)
{
pMin[0]=pMin[0]<buf[i]?pMin[0]:buf[i];
pMax[0]=pMax[0]>buf[i]?pMax[0]:buf[i];
pSum[0]+=buf[i];
}
pAvg[0]=(double)pSum[0]/(double)count;
}
int main()
{
char lineBuf[1024];//temporary line buffer
int numBuf[50];//the random number buffer
int min,max,sum;//sotre the min、max number and the sum
double avg;//store the average
int n;//store the number count
char c;
while(true)
{
//scan for the number count,any invalid inout will requests reinput
while(true)
{
printf("请输入生成随机数字的个数<1-50>:");
scanf("%d",&n);
if(n<1 || n>50)
{
gets(lineBuf);//sikp any line input
printf("错误,请输入1-50之间的数字.\n");
continue;
}
break;
}
//fill and print random numbers
fillNum(numBuf,n);
//find the max and the min number,also calculate the sum and the average
calcMaxMinSum(numBuf,n,&min,&max,&sum,&avg);
//print result
printf("Min Value :%d\nMax Value :%d\nSum :%d\nAverage:%.2lf\n",min,max,sum,avg);
printf("-----------------------------\n");
//test continus
while(true)
{
printf("要重新执行吗?<Y/N>");
scanf("%1s",&c);
if(c=='y' || c=='Y')
{
gets(lineBuf); //sikp any line input
break;
}
else if(c=='n' || c=='N')
{
return 0;
}
else
{
gets(lineBuf); //sikp any line input
printf("错误,请重新输入.\n");
}
}
printf("\n\n");
}
return 0;
}