求一个c语言编程大佬

2024-12-03 13:54:05
推荐回答(3个)
回答1:

#include

int k;

int sumOfFactor(int n)

{ int i,s=1;

for(i=2; i*i

if(n%i==0)s+=i+n/i;

if(i*i==n)s+=i;

return s;

}

int friendNum(int n)

{ k=sumOfFactor(n);

return k==sumOfFactor(n)&&n==sumOfFactor(k);

}

int main()

{ int n;

scanf("%d",&n);

if(friendNum(n))

printf("Find the friendly number of %d is %d.\n",n,k);

else

printf("There is no friendly number of %d.\n",n);

return 0;

}

回答2:

#include
int main() {
    int i,score,min,max,sum=0;
    for(i=0; i<7; i++) {
        printf("Input %d: ",i);
        scanf("%d",&score);
        if(i==0)
            min=max=score;
        else {
            if(score>max) max=score;
            if(score        }
        sum+=score;
    }
    printf("Sum=%d  Min=%d  Max=%d  AVG=%.2f",sum,min,max,1.0*(sum-max-min)/5);
}

回答3:

假设满分10.0分

int calc(float *num, int count, float *result) {
if (count <= 2) {
return -1;
}
float min = 10.0;
float max = 0.0;
float sum = 0.0;
for (int i=0; i if (num[i] < min) {
min = num[i];
} else if (num[i] > max) {
max = num[i];
} else {
sum += num[i];
}
}
*result = sum / (count - 2);
return 0;
}