question 1:
程序代码:
void fun(int *a,int n)//question 1
{
int i;
for(i=n-1;i>=0;i--)
printf("%d ",a[i]);
printf("\n");
}
question 2:
程序代码:
float avg(int *a,int n)//question 2
{
int i;float avg=0;
for(i=0;i<n;i++)
avg+=a[i];
return avg/n;
}
question 3:
程序代码:
void calu_Y(int n)//question 3
{
double y_1=0;
int i,y_2=0;
for(i=1;i<=n;i++)
y_1+=1.0/i;//calculate y=1+1/2+...+1/n
for(i=1;i<=98;i++)
y_2+=i*(i+1)*(i+2);//calculate y=1*2*3+2*3*4+...+98*99*100
printf("1+1/2+...+1/%d = %.2lf\n",n,y_1);
printf("1*2*3+2*3*4+...+98*99*100 = %d\n",y_2);
}
question 4:
程序代码:
void ques_4()
{
int i,a[10]={1,1,2,6,24,120,720,5040,40320,362880};
for(i=100;i<1000;i++)
if((a[i%10]+a[i/10%10]+a[i/100])==i)
printf("%d\t",i);
printf("\n");
}
question 5:
程序代码:
void ques_5(int a,int b,int c,int d)//compare a/b and c/d
{
if(a*d>b*c)printf("%d/%d > %d/%d\n",a,b,c,d);
else if(a*d==b*c)printf("%d/%d = %d/%d\n",a,b,c,d);
else printf("%d/%d < %d/%d\n",a,b,c,d);
}
question 6:
程序代码:
void ques_6()
{
long s,t=0,s1=1;
scanf("%ld",&s);
while(s>0)
{
t=t+s%10*s1;
s=s/100;
s1=s1*10;
}
printf("%d\n",t);
}