谁能帮我做下这个C语言题,一小时就要弄完!
2个回答
展开全部
差不多就这样吧,测试例子你多试几组
// 题目要求的输入语句你就自己弄吧,算法帮你实现了
#include <stdio.h>
#include <math.h>
#define N 10
float min(float x, float y);
float zxs(float i, float j, float k);
int jc(int n);
float avgs(int scores[], int n);
int gcd(int x, int y);
int main()
{
float i = 1.2, j = 4.2, k = -1.5;
int m = 4, n = 3;
int a[N] = {90,91,92,93,94,95,96,97,98,99};
int p = 15, q = 12;
printf("minnum = %f\n", zxs(i, j, k));
printf("%d! + %d! == %d\n", m, n, jc(m)+jc(n));
printf("avg = %f\n", avgs(a, N));
printf("%d and %d's gcd is %d\n", p, q, gcd(p,q));
return 0;
}
float min(float x, float y)
{
return x<y?x:y;
}
float zxs(float i, float j, float k) //第一题
{
float minnum = 0;
minnum = min(i, j);
minnum = min(k, minnum);
return minnum;
}
int jc(int n) //第二题
{
if(n==0 || n==1)
return 1;
else
return n*jc(n-1);
}
float avgs(int scores[], int n) //第三题
{
int i = 0;
float avg = 0;
for( ; i < n; ++i)
{
avg += scores[i];
}
return avg/n;
}
int gcd(int x, int y) //第四题
{
int z;
z = x % y;
while( z!=0 )
{
x = y;
y = z;
z = x%y;
}
return y;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询