题目还多个减号!
努力—前进—变老—退休—入土
#include <stdio.h> long tigui(long jia,long cheng) { if(cheng%jia==0) return jia; else tigui(cheng%jia,jia); } void yuefen(long *jia,long *cheng) { int i; while(1) { i=tigui(*jia,*cheng); if(i==1)break; else { *jia/=i; *cheng/=i; } } } int main(void) { int i,n,m=3,k=0; unsigned long zi,mu; do{ printf("n="); scanf("%d",&n); }while(n<1); for(zi=1,mu=2,i=3;i<=n;i++) { k++; if(k==m) { k=0,m++; zi=zi*i-mu; } else zi=mu+zi*i; mu*=i; yuefen(&zi,&mu); } printf("s="); if(zi>mu) { printf("%ld+",zi/mu); zi%=mu; } n==1?printf("1\n\n"):printf("%ld/%ld\n\n",zi,mu); getch(); return 0; }