记住,什么都要靠自己. 1. #include<stdio.h>
double fact(int n) { double fac; if(n==0) fac=1; else fac=n*fact(n-1); return fac; }
void main( ) { int k=0; double e=0,t; t=1/fact(k); while(t>=1e-6) { e+=t; t=1/fact(++k); } printf("%.12lf\n",e); } 2. #include<stdio.h>
void main( ) { int n,k; double sum,t; printf("Input n:"); scanf("%d",&n); sum=n; for(k=2;k<=100;k+=2) { t=(double)n/k; if((k/2)%2==0) sum+=t; else sum+=-t; } printf("sum=%lf\n",sum); } 3. #include<stdio.h> #include<conio.h>
void main( ) { int n,i,j; printf("Input n:"); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=0;j<i;j++) printf(" "); for(j=1;j<=n;j++) printf("*"); printf("\n"); } getch( ); }
3. #include<stdio.h> #include<conio.h>
void main( ) { int n,i,j; printf("Input n:"); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=0;j<i;j++) printf(" "); for(j=1;j<=n;j++) printf("*"); printf("\n"); } getch( ); } 2. #include<stdio.h>
void main( ) { int i,j,n; double sum,t; printf("Input n:"); scanf("%d",&n); sum=n; for(i=2;i<=100;i+=2) { t=(double)n/i; if((i/2)%2==0) sum+=t; else sum+=-t; } printf("sum=%lf\n",sum); } 1. #include<stdio.h>
double fac(int n) { double fact; if(n==0) fact=1; else fact=n*fac(n-1); return fact; }
void main( ) { double e,t; int k=0; e=0; t=1/fac(k); while(t>=1e-6) { e+=t; t=1/fac(++k); } printf("e=%.12lf\n",e); }