#include<stdio.h> int main(void) { int i; long int f[40]={1,1}; for(i=2;i<40;i++) f[i]=f[i-2]+f[i-1]; for(i=0;i<40;i++) { if(i%5==0)printf("\n"); printf("%12ld",f[i]); } }
作业系统: #include<stdio.h> #include<math.h> int main() { int sign(int x); int n,sum; int even(int n); int j,i; int prime(int m); int c,digit,in; int countdigit(int number,int digit); int choice=0,num,x; int is(int number); do{ printf("*****实验6:*****\n"); printf("*****计算分段函数的值:*****\n"); printf("*****使用函数计算奇数和:*****\n"); printf("*****利用函数计算素数个数并求和:*****\n"); printf("*****利用函数统计指定数字的个数:*****\n"); printf("*****使用函数输出水仙花数:*****\n"); printf("*****请选择题号:*****\n"); scanf("%d",&choice); switch(choice) { case 1: printf("清输入x:\n"); scanf("%d",&x); printf("f(%d)=%d\n",x,sign(x)); break; case 2: scanf("%d",&n); sum=0; while(n>0){ if(even(n)==0) sum=sum+n; scanf("%d",&n); } printf("The sum of the odd numbers is %d.\n",sum); break; case 3: int c,i,m,n,sum; scanf("%d%d",&m,&n); c=sum=0; for(i=m;i<=n;i++) if(prime(i)!=0) { c++; sum=sum+i; } printf("c=%d,sum=%d\n",c,sum);break; case 4: scanf("%d%d",&in,&digit); c=countdigit(in,digit); printf("number %d of digit %d:%d\n",in,digit,c); break; case 5: int a; scanf("%d%d",&m,&c); printf("result:\n"); for(a=m;a<=c;a++) if(is(a)!=0) printf("%d\n",a); break; case 0:break; } }while(choice!=0); return 0; } int sign(int x) { if(x>0) return 1; else if(x==0) return 0; else return -1; } int even(int n) { int y; if(n%2==0) y=1; else y=0; return y; } int prime(int m) { int j,i; if(m==1) return 0; j=sqrt(m); for(i=2;i<=j;i++) if(m%i==0) return 0; return 1; } int countdigit(int number,int digit) { int c; if(number<0) number=-number; c=0; do{ if(number%10==digit) c++; number=number/10; }while(number!=0); return c; } int is(int number) { int digit,sum,temp; temp=number; sum=0; while(temp!=0){ digit=temp%10; temp=temp/10; sum=sum+digit*digit*digit; } return sum==number; }