C语言程序运行时出现exe停止工作
解决时间 2021-02-12 11:26
- 提问者网友:捧腹剧
- 2021-02-12 03:38
#include "stdio.h"
#include "stdlib.h"
void sort(int *a,int len)
{
int i, j;
for(i=len-1; i>=0; i--) {
for(j=0; j if(a[j] < a[j+1]){
int temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
} int n,k,stone[128];
int min=0,i,tdata[128],a[128];
int Fmin()
{
int len = n;
for( i=0; i tdata[i] = stone[i];
while (len % (k - 1) != 1)
{
len++;
tdata[len-1]=0;
}
int p =0;
while(1)
{
if(len < k) break;
int temp = 0;
for (int j=1; j<=k; j++)
{
temp += tdata[len-j];
}
// printf("%d\n",temp);
a[p++] = temp;
tdata[len-k] = temp;
len = len - k + 1;
sort(tdata,len);
}
for(int j=0; j
min = min + a[j];
return min;
}
}
int Fmax()
{
int max = 0;
int temp = stone[0] + stone[1];
max = temp;
for (int i=2; i<=k;i++)
{
temp = temp + stone[i];
max += temp;
}
return max;
}
int main()
{
int i;
int n,k,stone[128];
scanf("%d%d",&n,&k);
for( i=0; i
scanf("%d",&stone[i]);
sort(stone,n);
printf("%d %d\n",Fmin(),Fmax());
return 0;
}
}
最佳答案
- 五星知识达人网友:我住北渡口
- 2021-02-12 04:42
void sort(int *a,int len)
{
int i, j;
for(i=len-1; i>=0; i--) {
for(j=0; j
if(a[j] < a[j+1]){
int temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
int main()
{
int i;
int n,k,stone[128];
//scanf("%d%d",&n,&k); k有什么用?
scanf("%d",&n);
for( i=0; i
scanf("%d",&stone[i]);
sort(stone,n);
//printf("%d %d\n",Fmin(),Fmax());
printf("%d %d\n", stone[0], stone[n-1] ); //排序后,大小自然就得到了
return 0;
}
全部回答
# include
int main(void)
{
float i, j, k;
float average, average1, average2, average3;
float sum1=0, sum2=0, sum3=0;
int t = 0;
char ch;
do
{
t++;
printf("学生%d\n", t);
printf("语文成绩:\n");
scanf("%f", &i);
printf("数学成绩:\n");
scanf("%f", &j);
printf("英语成绩:\n");
scanf("%f", &k);
average = (i+j+k)/3;
sum1 += i;
sum2 += j;
sum3 += k;
printf("该生平均成绩为:%f\n", average);
printf("还要继续吗?(y/n)\n");//斜杠写错了
fflush(stdin);//要清除回车
scanf(" %c", &ch); //少了&
}
while ('y' == ch || 'y' == ch);
average1 = sum1/t;
average2 = sum2/t;
average3 = sum3/t;
printf("所以学生语文成绩平均值为:%f", average1);
printf("所以学生数学成绩平均值为:%f", average2);
printf("所以学生英语成绩平均值为:%f", average3);
return 0;
}
我要举报
大家都在看
推荐资讯