C语言练习题
1.
1,2,1,2,3,2,1,2,3,4,3,2,1,2,3,4,5,4,3,2,1,2,3,4,5,6,5,4,3,2,1
void printn(int n)
{
for(int i = 2; i < = n; i++)
printf("%d ", i);
for(int j = n - 1; j > 0; j--)
printf("%d ", j);
}
int main()
{
int n;
scanf("%d", n);
printf("1 ");
for(int i = 2; i <= n; i++)
printf(i);
return 0;
}
2.用函数求Cmn=m!/(n!(m-n)!)
#include<stdio.h>
double app(double d)
{
double i,sum=1;
for(i=1;i<=d;i++)
{
sum=sum*i;
}
return(sum);
}
int main()
{
double m,n,a,b,c;
while(scanf("%lf %lf",&m,&n)!=EOF)
{
a=app(m);
b=app(n);
c=app(m-n);
printf("%.0f\n",a/(b*c));
}
}