程序设计题练习.ppt

程序设计题练习.ppt

【程序设计2 】:用while语句求1~100的累计和(377)。 1:#include stdio.h 2:void wwjt(); 3:int fun(int n) 4:{ /**********Program**********/ 5: 6: 7: 8:/********** End **********/ } 9:void main(): 10: { int sum = 0; 11:sum=fun(100); 12: printf (“sum = %d\n”, sum); 13: wwjt(); } void wwjt() { FILE *IN,*OUT; int i; int iIN,iOUT; IN=fopen(in.dat,r); if(IN==NULL) {printf(Please Verify The Currernt Dir..it May Be Changed); } OUT=fopen(out.dat,w); if(OUT==NULL) {printf(Please Verify The Current Dir.. it May Be Changed); } for(i=0;i5;i++) { fscanf(IN,%d,iIN); iOUT=fun(iIN); fprintf(OUT,%d\n,iOUT); } fclose(IN); fclose(OUT); } 【程序设计3 】 编写函数求3!+6!+9!+12!+15+18!+21!。 1: #include stdio.h 2: void wwjt(); 3: float sum(int n) 4: { /**********Program**********/ 5: 6: 7: 8: /********** End **********/ } 9: main() 10: { 11: printf(this sum=%e\n,sum(21)); 12: wwjt(); } void wwjt() { FILE *IN,*OUT; int i; int iIN,iOUT; IN=fopen(in.dat,r); if(IN==NULL) {printf(Please Verify The Currernt Dir..it May Be Changed); } OUT=fopen(out.dat,w); if(OUT==NULL) {printf(Please Verify The Current Dir.. it May Be Changed); } for(i=0;i5;i++) { fscanf(IN,%d,iIN); iOUT=fun(iIN); fprintf(OUT,%d\n,iOUT); } fclose(IN); fclose(OUT); } 【程序设计6 】功能:用函数实现字符串的复制, 不允许用strcpy()函数。 1: #include stdio.h 2: void wwjt(); 3: void copy(char str1[],char str2[]) { 4:/**********Program**********/ 5: 6:/********** End **********/ } 7:main() { 8: void copy(); 9: char c1[40],c2[40]; 10: gets(c1); 12: copy(c1,c2); 13: puts(c2); 14: wwjt(); } 【程序设计7】题目:输入华氏温度求摄氏温度。转换公式为 c=5/9(f-32),输出结果取两位小数。 1: #include stdio.h 2: void wwjt(); 3: double fun(double m) 4: {/**********Program**********/ 5: 6: 7: /********** End **********/} 8: void main() { 9: double c,f; 10: printf(请输入一个华氏温度:); 11: scanf(%f,f); 12: c=fun(f); 13: printf(摄氏温度为:%5.2f\n,c); 14: wwjt(); } 【程序设计8】功能:求n阶方阵主、副对角线上的元素之积。 1:#define N 4 2:#include stdlib.h 3:#include stdio.h

文档评论(0)

1亿VIP精品文档

相关文档