高分求几道C的做法.速度.
来源:百度知道 编辑:UC知道 时间:2024/05/21 16:20:41
1.编写函数fun,它的功能是:求出1000以内能被7或11整除,但不能同时被7和11整除的数,通过函数名返回个数。
2.在6至5000内找出所有的亲密数对.
说明:若a、b为1对亲密数,则a的因子和等于b、b的因子和等于a、且a不等于b。
如:220、284是1对亲密数,284、220也是1对亲密数。
3.编写函数fun,它的功能是:求Fibonacci数列中大于t的最小的一个数,结果由函数返回。
其中Fibonacci数列F(n)的定义为:
F(0)=0,F(1)=1 F(n)=F(n-1)+F(n-2) 例如:当t = 1000时,函数值为:1597
2.在6至5000内找出所有的亲密数对.
说明:若a、b为1对亲密数,则a的因子和等于b、b的因子和等于a、且a不等于b。
如:220、284是1对亲密数,284、220也是1对亲密数。
3.编写函数fun,它的功能是:求Fibonacci数列中大于t的最小的一个数,结果由函数返回。
其中Fibonacci数列F(n)的定义为:
F(0)=0,F(1)=1 F(n)=F(n-1)+F(n-2) 例如:当t = 1000时,函数值为:1597
1.
int Fibonacc(void)
{
int i = 1000 ;
int j = 0 ;
int num ;
for(j = 1 ; j < i ; j++)
{
if((j % 7 == 0 || j % 11 == 0 ) &&(j % 77 != 0))
{
num++ ;
}
}
return num ;
}
3.
long long Fibonacc(int n)
{
if(n == 0 || n == 1)
return n ;
else
return Fibonacc(n-1) + Fibonacc(n - 2) ;
}
long long fun(int t)
{
return Fibonacc(t + 1);
}
int fun(void)
{int i,j,num=0;
for(i=0;i<1000;i++)
{if(i%7==0)
{if(i%11!=0)num++;}
else
{if(i%11==0)num++;}
}
return num;
}
下面两个很麻烦唉,交给别人啦
1.
#include <stdio.h>
void main()
{
int i, j, arr[20000];
for (i = 1, j = 0; i <= 1000; i++)
{
if ((i % 7 == 0) ^ (i % 11 == 0))
{
arr[j++] = i;
}
}
for (i = 0; i < j; i++)
{