无聊中,找了两道小学奥赛题拿C语言编写(高手请绕道)
题目:观察:1+2+3 2+4+6 3+6+9。。。那么,前1995个算式的和是多少?代码:
#include "stdio.h"
int add(int a,int b,int c)
{
int d=0;
d=a+b+c;;
return d;
}
main()
{
int i=0;long int n=0l;int x=0;
for(i=1;i<=1995;i++)
{
n=n+(long)add(i,i*2,i*3);
}
printf("%ld\n",n);
scanf("%d",&x);
}
结果:11946060
====================================
题目:计算:1/(3*5)+1/(5*7)+1/(7*9)+...+1/()
代码:
#include "stdio.h"
#include "math.h"
double ad(int x,int y)
{
double z=0.0;
z=1.0/(x*y);
return z;
}
main()
{
int a=0;double b=0.0;int n=0;
for(a=1;a<=1993;a=a+2)
{
b=b+ad(a,a+2);
}
printf("%f\n",b);
scanf("%d",&n);
}
结果:0.449749