计算机 - printf("n = %d\n",n); fib=fun(n);...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: printf("n = %d\n",n); fib=fun(n); printf("fib = %d\n\n",fib); } ˼· һswitchжķֺš ڶcase 1ûз䣬ҲӦΪreturn 1;ӦΪcase 1: return 1; case 2:return 1; ********************************************************************** ijѧļ¼ѧš8ſγ̳ɼƽɣѧź8ſγ̵ijɼ идfun,Ĺǣѧƽַڼ¼ aveԱС 磬ѧijɼǣ85.5,76,69.5,85,91,72,64.5,87.5,ƽӦ ǣ78.875 ע: ԴļPROG1.CС Ķmainеκݣںfunλ д䡣 Դ #include <stdio.h> #define N 8 typedef struct { char num[10]; double s[N]; double ave; } STREC; void fun(STREC *a) { } main() { STREC s={"GA005",85.5,76,69.5,85,91,72,64.5,87.5}; int i; fun( &s ); printf("The %s's student data:\n", s.num); for(i=0;i<N; i++) printf("%4.1f\n",s.s[i]); printf("\nave=%7.3f\n",s.ave); NONO(); } NONO() {/* ڴļݣúݣرļ */ FILE *out ; int i,j ; STREC s[10] = { {"GA005",85.5,76,69.5,85,91,72,64.5,87.5}, {"GA001",82.5,66,76.5,76,89,76,46.5,78.5}, {"GA002",72.5,56,66.5,66,79,68,46.5,58.5}, {"GA003",92.5,76,86.5,86,99,86,56.5,88.5}, {"GA004",82,66.5,46.5,56,76,75,76.5,63.5}, {"GA006",75.5,74,71.5,85,81,79,64.5,71.5}, {"GA007",92.5,61,72.5,84,79,75,66.5,72.5}, {"GA008",72.5,86,73.5,80,69,63,76.5,53.5}, {"GA009",66.5,71,74.5,70,61,82,86.5,58.5}, {"GA010",76,66.5,75.5,60,76,71,96.5,93.5}, }; out = fopen("c:\\test\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fun(&s[i]) ; fprintf(out, "%7.3f\n", s[i].ave) ; } fclose(out) ; } ˼· ¼ṹѧγ̳ɼƽֵԷڸü¼ṹС ο #include <stdio.h> #define N 8 typedef struct { char num[10]; double s[N]; double ave; } STREC; void fun(STREC *a) { int i ; for(i = 0 ; i < N ; i++) a->ave = a->ave + a->s[i] ; a->ave /= N ; } main() { STREC s={"GA005",85.5,76,69.5,85,91,72,64.5,87.5}; int i; fun( &s ); printf("The %s's student data:\n", s.num); for(i=0;i<N; i++) printf("%4.1f\n",s.s[i]); printf("\nave=%7.3f\n",s.ave); NONO(); } NONO() {/* ڴļݣúݣرļ */ FILE *out ; int i,j ; STREC s[10] = { {"GA005",85.5,76,69.5,85,91,72,64.5,87.5}, {"GA001",82.5,66,76.5,76,89,76,46.5,78.5}, {"GA002",72.5,56,66.5,66,79,68,46.5,58.5}, {"GA003",92.5,76,86.5,86,99,86,56.5,88.5}, {"GA004",82,66.5,46.5,56,76,75,76.5,63.5}, {"GA006",75.5,74,71.5,85,81,79,64.5,71.5}, {"GA007",92.5,61,72.5,84,79,75,66.5,72.5}, {"GA008",72.5,86,73.5,80,69,63,76.5,53.5}, {"GA009",66.5,71,74.5,70,61,82,86.5,58.5}, {"GA010",76,66.5,75.5,60,76,71,96.5,93.5}, }; out = fopen("c:\\test\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fun(&s[i]) ; fprintf(out, "%7.3f\n", s[i].ave) ; } fclose(out) ; } 58ף УfunĹǣβsַָұߵnַ βtַָУγһ´sַָijСn ַƵβtַָС 磬βsַָΪ:abcdefghnֵΪ5ִкtַָ еַӦΪdefgh ڳ»ߴȷݲ»ɾ, ʹóȷĽ ע⣺ԴڿļµBLANK1.CС лɾУҲøijĽṹ Դ #include <stdio.h> #include <string.h> #define N 80 void fun(char *s, int n, char *t) { int len,i,j=0; len=strlen(s); /**********found**********/ if(n>=len) strcpy(__1__); else { /**********found**********/ for(i=len-n; i<=len-1; i++) t[j++]= __2__ ; /**********found**********/ t[j]= __3__ ; } } main() { char s[N],t[N]; int n; printf("Enter a string: ");gets(s)...
View Full Document

This note was uploaded on 02/23/2012 for the course CS 2000 taught by Professor Peter during the Spring '12 term at Appalachian State.

Ask a homework question - tutors are online