四个学校编程问题,要按题目要求来,求大神解答,谢谢
四个学校编程问题,要按题目要求来,求大神解答,谢谢 本帖最后由 baige 于 2020-9-20 20:13 编辑#include <stdio.h>
#include <math.h>
int main() {
int m, f = 1, i;
scanf("%d", &m);
if (m % 2 == 0 && m != 2|| m <= 1)f = 0;
for (i = 3; i <= sqrt(m); i += 2) {
if (m % i == 0) {
f = 0;
break;
}
}
if (f)printf("%d is a prime\n", m);
else printf("%d is not a prime\n", m);
return 0;
} #include <stdio.h>
int main(){
int s = 0;
int i;
for(i = 1; i <= 1000; i++){
if(i%5!=0&&i%7!=0){
s += i;
}
}
printf("s=%d\n",s);
return 0;
} #include <stdio.h>
int main(void){
int n,k;
ffloat score, sum, ave;
for(n = 1; n <= 4; n++){
sum = 0.0;
for(k = 1; k <= 3; k++){
scanf("%f",&score);
sum += score;
}
ave = sum / 3.0;
printf("NO%d:%.1f\n",n,ave);
}
return 0;
} #include <stdio.h>
double average(int arr[], int n){
int k = 0, i;
double s;
s = 0;
for(i = 0; i < n; i++)
if(arr%2==1){// == 不是 =
s = s+arr;
k++;
}
return s/k;
}
int main(){
int a, i;
double s;
for(i = 0; i < 12; i++)
scanf("%d",&a);
s = average(a,12);//a不是a
printf("The result is:%.2f\n",s);
return 0;
} 小生我怕怕~~
页:
[1]