2020-12-06

#include <stdio.h>
#include <stdlib.h>
#include<time.h>
#define N 30
double sumArr(double a[],int m);
void printfArr(double a[],int m);
int judgeMax(double a[],int m,int i);
int main()
{
srand(time(NULL));
double a[N]={0};
double money,max,min;
int people,i;
while(1)
{
printf(“总金额:”);scanf("%lf",&money);
printf(“个数:”);scanf("%d",&people);
printf(“最大金额:”);scanf("%lf",&max);
printf(“最小金额:”);scanf("%lf",&min);
if(min>max||people>(int)money||max>money||minpeople>money||maxpeople<money)
{
printf(“输入错误,请检查错误\n”);
continue;
}
printf(“恭喜发财\n”) ;
while(1)
{
for(i=0;i<people-1;i++)
a[i]=min+((max-min)*rand())/RAND_MAX;
if(sumArr(a,people-1)<money&&sumArr(a,people-1)<(money-min)&&sumArr(a,people-1)>(money-max))
{
a[people-1]=money-sumArr(a,people-1);
break;
}
else
continue;

}
printfArr(a,people);
printf("是否继续派发红包\n否输入N\n是请按任意键\n");
char  ch=getch();
if(ch=='N'||ch=='n')
    break;
}

}
//数组的和
double sumArr(double a[],int m)
{
int i;
double sum=0;
for(i=0;i<m;i++)
{
sum+=a[i];
}
return sum;
}
//数组输出
void printfArr(double a[],int m)
{
int i;
for(i=0; i<m; i++)
{
printf(“第%d个人%.2lf”,i+1,a[i]);
if(judgeMax(a,m,i)1)
printf("(运气王)");
printf("\n");
}
}
//判断最大值形参m数组总个数,第i个 (运气王判断)
int judgeMax(double a[],int m,int i)
{
int j=0;
double max = a[0];
for(j=1;j<m;j++)
{
if(a[j]>max)
max=a[j];
}
if(max
a[i])
return 1;
else
return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值