本文目录一览:
C语言作业题1
#includestdio.h
#define PI 3.1415926
int div(double s, double a[], int n)
{
int i, re = 0;
for(i = 0; i n; i++)
re += (int)(a[i] * a[i] * PI / s);
return re;
}
int main()
{
int c, n, p, i;
double a[10010], sum, smax, min, max;
scanf("%d", c);
while(c--)
{
scanf("%d %d", n, p);
p++;
sum = smax = 0.0;
for(i = 0; i n; i++)
{
scanf("%lf", a[i]);
sum += PI * a[i] * a[i];
if(PI * a[i] * a[i] smax)
smax = PI * a[i] * a[i];
}
min = smax / p / 2.0;
max = sum / p + 1;
while(1)
{
if(div(min, a, n) = p div(max, a, n) p max - min 1e-6)
break;
if(div((max + min) / 2.0, a, n) p)
max = (max + min) / 2.0;
else if(div((max + min) / 2.0, a, n) = p)
min = (max + min) / 2.0;
}
printf("%.4lf\n", min);
}
return 0;
}
C语言作业。1.用键盘输入一个数,然后做以下判断:如果是5就打印big,否则打印small
1、
void main()
{
int x;
scanf("%d",x);
if(x == 5)
printf("big");
else
printf("small");
}
2、
void main()
{
int a[10] = {1,2,3,4,5,6,7,8,9,10};
int x,i;
scanf("%d",x);
for(i = 0;i 10;i++)
if(a[i] == x)
{
printf("有%d这个数",x);
return;
}
printf("没有%d这个数",x);
return;
}
C语言作业 !!!!!
1.
k2*i+1
2.
!fg
3.
j=i
4.
sum+=1.0/t