1、编程题1、 功能:判断一个整数w的各位数字平方之和能否被5整除,可以被5整除则返回1,否则返回0。#include #includeconio.hvoid wwjt(); int fun(int w) /*Program*/ /* End */ main() int m; printf(Enter m: ); scanf(%d, &m); printf(nThe result is %dn, fun(m); wwjt();void wwjt() FILE *IN,*OUT; int c ; int t; int o; IN=fopen(in.dat,r); if(IN=NULL) printf
2、(Read FILE Error); OUT=fopen(out.dat,w); if(OUT=NULL) printf(Write FILE Error); for(c=1;c=5;c+) fscanf(IN,%d,&t); o=fun(t); fprintf(OUT,%dn,o); fclose(IN); fclose(OUT);2、功能:求一个大于10的n位整数的后n-1位的数。#include #includeconio.hvoid wwjt(); int fun(int w) /*Program*/ /* End */ main() int m; printf(Enter m: );
3、 scanf(%d, &m); printf(nThe result is %dn, fun(m); wwjt();void wwjt() FILE *IN,*OUT; int c ; int t; int o; IN=fopen(in.dat,r); if(IN=NULL) printf(Read FILE Error); OUT=fopen(out.dat,w); if(OUT=NULL) printf(Write FILE Error); for(c=1;c=5;c+) fscanf(IN,%d,&t); o=fun(t); fprintf(OUT,%dn,o); fclose(IN);
4、 fclose(OUT);3、功能:对某一正数的值保留2位小数,并对第三位进行四舍五入。#include #includeconio.hvoid wwjt(); double fun(float h) /*Program*/ /* End */ main() float m; printf(Enter m: ); scanf(%f, &m); printf(nThe result is %8.2fn, fun(m); wwjt(); void wwjt() FILE *IN,*OUT; int s ; float t; double o; IN=fopen(in.dat,r); if(IN=N
5、ULL) printf(Read FILE Error); OUT=fopen(out.dat,w); if(OUT=NULL) printf(Write FILE Error); for(s=1;s=5;s+) fscanf(IN,%f,&t); o=fun(t); fprintf(OUT,%8.2fn,o); fclose(IN); fclose(OUT);4、功能:找出一个大于给定整数且紧随这个整数的素数。#include #includeconio.hvoid wwjt(); int fun(int n) /*Program*/ /* End */ main() int m; prin
6、tf(Enter m: ); scanf(%d, &m); printf(nThe result is %dn, fun(m); wwjt(); void wwjt() FILE *IN,*OUT; int s ; int t; int o; IN=fopen(in.dat,r); if(IN=NULL) printf(Read FILE Error); OUT=fopen(out.dat,w); if(OUT=NULL) printf(Write FILE Error); for(s=1;s=5;s+) fscanf(IN,%d,&t); o=fun(t); fprintf(OUT,%dn,
7、o); fclose(IN); fclose(OUT);5、功能:判断整数x是否是同构数。若是同构数,函数返回1;否则返回0。要求:x的值不大于100。说明:所谓“同构数”是指这样的数,这个数出现在它的平方数的右边。例如:输入整数5,5的平方数是25,5是25中右侧的数,所以5是同构数。#include void wwjt(); int fun(int x) /*Program*/ /* End */main() int x,y; printf(nPlease enter a integer numbers:); scanf(%d,&x); if(x100) printf(data error
8、!n); exit(0); y=fun(x); if(y) printf(%d YESn,x); else printf(%d NOn,x); wwjt(); void wwjt() FILE *IN,*OUT; int n,t; int o; IN=fopen(in.dat,r); if(IN=NULL) printf(Read FILE Error); OUT=fopen(out.dat,w); if(OUT=NULL) printf(Write FILE Error); for(t = 0 ; t 5 ; t+) fscanf(IN, %d, &n) ; o=fun(n); fprint
9、f(OUT, %dn,o ) ; fclose(IN); fclose(OUT);6、功能:将两个两位数的正整数a、b合并形成一个整数放在c中。合并的方式是:将a数的十位和个位数依次放在c数的百位和个位上,b数的十位和个位数依次放在c数的十位和千位上。 例如:当a45,b=12。结果为:c=2415。7、功能:求解如下序列的前10项之和: 2/1,3/2,5/3,8/5,13/8,21/13,要求:结果精确到小数点后2位。#include stdio.hfloat fun(int n) /*Program*/ /* End */main() FILE *OUT; float s; OUT=fo
10、pen(bc02.out,w); if(OUT=NULL) printf(Cant open the file.n); s=fun(10); printf(%.2fn,s); fprintf(OUT,%.2fn,s); fclose(OUT);_8、功能:求表达式1+1/2!+1/3!+1/4!+1/5!之和。要求:结果精确到小数点后3位。#include stdio.hdouble fun(int n)/*Program*/ /* End */main() FILE *OUT; double s; OUT=fopen(bc04.out,w); if(OUT=NULL) printf(Cant
11、 open the file.n); s=fun(5); printf(%.3lfn,s); fprintf(OUT,%.3lfn,s); fclose(OUT);_9、功能:求2-100之内的所有素数,并将其按存放到一维数组中,要求将找到的所有素数按每行5个数据的形式输出。#include stdio.h#include#define M 50void fun(int a)/*Program*/ /* End */main() FILE *OUT; int aM=0,i; clrscr(); OUT=fopen(bc05.out,w); if(OUT=NULL) printf(Cant op
12、en the file.n); fun(a); for(i=0;ai!=0;i+) if(i%5=0) printf(n); fputc(n,OUT); printf(%5d,ai); fprintf(OUT,%5d,ai); fclose(OUT);_10、功能:统计出若干个学生的平均成绩,最高分以及得最高分的人数。例如:输入10名学生的成绩分别为92,87,68,56,92, 84,67,75,92,66,则输出平均成绩为77.9,最高分为92,得最高分的人数为3人。#include void wwjt(); float Max=0;int J=0;float fun(float arra
13、y,int n) /*Program*/ /* End */ main( ) float a10,ave; int i=0; for(i=0;i10;i+) scanf(%f,&ai); ave=fun(a,10); printf(ave=%fn,ave); printf(max=%fn,Max); printf(Total:%dn,J); wwjt();void wwjt() FILE *IN,*OUT; float iIN10,iOUT; int iCOUNT; IN=fopen(in.dat,r); if(IN=NULL) printf(Please Verify The Currern
14、t Dir.it May Be Changed); OUT=fopen(out.dat,w); if(OUT=NULL) printf(Please Verify The Current Dir. it May Be Changed); for(iCOUNT=0;iCOUNT10;iCOUNT+) fscanf(IN,%f,&iINiCOUNT); iOUT=fun(iIN,10); fprintf(OUT,%f %fn,iOUT,Max); fclose(IN); fclose(OUT);11、功能:按顺序将一个4位的正整数每一位上的数字存到一维数组,然后再输出。例如输入5678,则输出结果
15、为 5 6 7 8。 要求:数字拆分必须用循环实现,不得只用顺序结构。#include stdio.hvoid fun(int n,int a) /*Program*/* End */main() FILE *OUT; int n=5678,a4,i,j; OUT=fopen(bc03.out,w); if(OUT=NULL) printf(Cant open the file.n); fun(n,a); for(i=0;i4;i+) printf(%2d,ai); fprintf(OUT,%2d,ai); fclose(OUT);_12、功能:从字符串s中删除指定的字符c,多次出现的全部删除
16、。#include stdio.hfun(char s,char c) /*Program*/* End */main() static char str=turbo c and borland c+; char c=a; fun(str,c); printf(str=%sn,str); yzj();yzj() FILE *IN,*OUT; char sIN80,cIN; int i; IN=fopen(bc01.in,r); if(IN=NULL) printf(Please Verify The Currernt INDir.It May Be Changed); OUT=fopen(bc
17、01.out,w); if(OUT=NULL) printf(Please Verify The Current OUTDir. It May Be Changed); fgets(sIN,25,IN); cIN=getc(IN); fun(sIN,cIN); fprintf(OUT,%sn,sIN); fclose(IN); fclose(OUT);_13、功能:输入一个字符串,过滤此串,只保留串中的字母字符,并统计新生成串中包含的字母个数。例如:输入的字符串为ab234$df4,新生成的串为abdf。#include #include #define N 80void wwjt(); fu
18、n(char *ptr) /*Program*/ /* End */ main() char strN; int s; printf(input a string:);gets(str); printf(The origINal string is :); puts(str); s=fun(str); printf(The new string is :);puts(str); printf(There are %d char IN the new string.,s); wwjt();void wwjt() FILE *IN,*OUT; char sinN; int iOUT; IN=fop
19、en(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); fscanf(IN,%s,sin); iOUT=fun(sin); fprintf(OUT,%d %sn,iOUT,sin); fclose(IN); fclose(OUT);14、功能:求5行5列矩阵的主、副对角线上元素之和。注意:两条对角线相
20、交的元素只加一次。#include #define M 5void wwjt(); int fun(int aMM) /*Program*/ /* End */ main() int aMM=1,3,5,7,9,2,4,6,8,10,2,3,4,5,6,4,5,6,7,8,1,3,4,5,6; int y; y=fun(a); printf(s=%dn,y); wwjt();void wwjt() FILE *IN,*OUT; int iINMM,iOUT; int i,j; 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;iM;i+) for(j=0;jM;j+) fscanf(IN,%d,&iINij); iOUT=fun(iIN); fprintf(OUT,%dn,iOUT); fclose(IN); fclose(OUT);
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1