计算机 编程题大全

上传人:wt****50 文档编号:36993399 上传时间:2018-04-05 格式:DOC 页数:59 大小:236.50KB
返回 下载 相关 举报
计算机 编程题大全_第1页
第1页 / 共59页
计算机 编程题大全_第2页
第2页 / 共59页
计算机 编程题大全_第3页
第3页 / 共59页
计算机 编程题大全_第4页
第4页 / 共59页
计算机 编程题大全_第5页
第5页 / 共59页
点击查看更多>>
资源描述

《计算机 编程题大全》由会员分享,可在线阅读,更多相关《计算机 编程题大全(59页珍藏版)》请在金锄头文库上搜索。

1、1编程题1m 个人的成绩存放在 score 数组中,请编写函数 fun,它的功能是:将低于平均分的人数作为函数值返回,将 低于平均分的分数放在 below 所指的数组中。例如,当 score 数组中的数据为 10、20、30、40、50、60、70、80、90 时,函数返回的人数应该是 4,below 中的数据应为 10、20、30、40。 第一个 for 循环用来计算 score 数组中分数的总和,然后用 aver/=m 求出平均值,第二个循环用来找出小于平 均分的元素,并放到数组 below 中,这里要注意 j 的递增方式。 #include #include #include int f

2、un(int score,int m,int below) int i,j=0,aver=0;for(i=0;i #include void fun(int *a,int *n) int i,m=0; for(i=1;i #include void fun(int x,int pp,int *n) int i,j=0;for( i=1;i #include void fun(char *tt,int pp) int i;for(i=0;i=a) pp*tt-97+; main( ) char aa1000;int bb26,k;clrscr( );printf(“nPlease enter a

3、 char string:“);scanf(“%s“,aa);fun(aa,bb);for(k=0;k #include void fun(int m,int k,int xx) int i,j=0,p=m+1;do for( i=2;i=p) xxj+=p;p+; while(j #include #define LEN 20 void fun (char a,char b ,int n) int i,k=0;for(i=0;ai!=0;i+)if(i!=n) bk+=ai;bk=0; main( ) FILE *wf ; char strlLEN,str2LEN; int n; print

4、f (“Enter the string:n“) ;gets(strl);printf (“Enter the position deleted:“);scanf (“%d“,fun(strl,str2,n);printf (“The new string is:%s n“,str2);wf=fopen(“out.dat“,“w“);fun(“world“,str2,3);fprintf(wf,“%s“,str2);fclose(wf);7请编写一个函数 int fun(int *s,int t,int *k),用来求出数组的最大元素在数组中的下标并存放在 k 所指的存4储单元中。例如,输入如

5、下整数:876 675 896 101 301 401 980 431 451 777 则输出结果为:6,980。 #include #include int fun(int *s,int t,int *k) int i,max; max=s0; for( i=0;imax) max=si;*k=i; main( ) int a10=876,675,896,101,301, 401,980,431,451,777,k;fun(a,10,printf(“%d,%dn“,k,ak); 8编写函数 fun,函数的功能是:根据以下公式计算 s,计算结果作为函数值返回;n 通过形参传入。s=1+1/(1

6、+2) +1/(1+2+3)+.+1/(1+2+3+4+.+n),例如:若 n 的值为 11 时,函数的值为 1.833333。 #include float fun(int n) int i,sum=1;float s=1;for(i=2;in。p=m!/n!(m-n)!。例如:m=12,n=8 时,运行结果为 495.000000。 #include #include float fun( int m,int n) int i,j,k;long int t=1,s=1,p=1;float q;for(i=1;i #include #include float fun() float x0,

7、x1=0;do x0=x1;x1=cos(x0);while( fabs(x0-x1)1e-006);return x1; main( ) printf(“root=%fn“,fun(); 11下列程序定义了 NN 的二维数组,并在主函数中自动赋值。请编写函数 fun(int aN),该函数的功能是: 使数组左下半三角元素中的值全部置成 0。例如:a 数组中的值为该题的关键是如何表示出左下半角的元素, 当从上往下到第 i 行时只有左边的 i 个元素要置为 0(每行总是如此)。用外层 for 来控制行而内嵌的 for 来控 制每行的左边元素,故而在内嵌 for 中 j 最大只能循环到 i(即表示

8、出第 i 行左边的 i 个元素)。 197 097 a=238008 456 ,则返回主程序后 a 数组中的值应为 000 。 #include #include #include #define N 5 int fun(int aN) int i,j; for(i=0;i #include #include #define N 5 double fun (int wN) int i,t=0;double s=0;for(i=0;i #include #define M 4 #define N 5 int fun(int aMN) int sum=0,i; for(i=0;i #include

9、 unsigned fun( unsigned w ) if(w=10000) return w%10000;if(w=1000) return w%1000;if(w=100) return w%100;return w%10; main( ) unsigned x;printf( “enter a integer number:“ );scanf( “%u“,if(x #include float fun(float h) long t;h=h*1000;t=(h+5)/10;return (float)t/100; main( ) float a;printf(“Enter a:“);

10、scanf(“%f“,printf(“The original data is:“);printf(“%fnn“,a);printf(“The result :%6.2fn“,fun(a); 17请编一个函数 fun(char *s),该函数的功能是把字符串中的内容逆置。例如:字符串中原有的字符串为 abcdefg,则调用该函数后,串中的内容为 gfedcba。该题的算法是先分别找出字符串的两头,然后同时逐一往中9间移动,每移动一次都进行两字符的位置对换,直到中间字符(用 s+i #include #include #define N 81 fun(char *s) int i=0,t,n=s

11、trlen(s);for(;s+i #include int fun(int array33) int i,j,t; for(i=0;i #include int fun(char s,int c) int i,k=0; for(i=0;si;i+) if(si!=c) sk+=si; sk=0; main( ) static char str=“turbo c and borland c+“; char ch; clrscr(); printf(“ :%sn“,str); printf(“ :“); scanf(“%c“, fun(str,ch); printf(“str=%sn“,str)

12、; 20.编写函数 int fun(int lim,int aaMAX),该函数的功能是求出小于或等于 lim 的所有素数并放在 aa 数组中, 该函数返回所求出的素数的个数。 注:循环 for(i=2;i=k)用于判断在上一个 for()循环中 i 能否走到 k,如果能则表示在 2 到 k-1 的数都不能整除 k,即 k 为素数。 #include #include #define MAX 100 int fun( int lim, int aaMAX) int i,j=0,k;for( k=2; k=k) aaj+=k;return j; main( ) int limit,i,sum;i

13、nt aaMAX;printf(“n input a integer number:“);scanf(“ %d“,sum=fun(limit,aa);for(i=0; i #include #include int fun(char *s,int num) int i,j,t;for(i=1;i #include #define N 8 struct slist double s;12struct slist *next; typedef struct slist STREC; double fun( STREC *h ) double max ; int i ; max=h-s;for(i=

14、0 ; ismax) max=(h+i)-s;return max; STREC * creat( double *s) STREC *h,*p,*q; int i=0;h=p=(STREC*)malloc(sizeof(STREC);p-s=0;while(is=si; i+; p-next=q; p=q;p-next=0;return h; outlist( STREC *h) STREC *p;p=h-next; printf(“head“);do printf(“-%2.0f“,p-s); p=p-next; while(p!=0);printf(“nn“); main( ) doub

15、le sN=85,76,69,85,91,72,64,87, max;STREC *h;h=creat(s); outlist(h);max=fun( h );printf(“max=%6.1fn“,max);23.请编写函数 fun,该函数的功能是:判断字符串是否为回文?若是则函数返回 1,主函数中输出 YES,否则返回 0,主函数中输出 N0。回文是指顺读和倒读都一样的字符串。 例如,字符串 LEVEL 是回文,而字符串 123312 就不是回文。 #include #define N 80 int fun(char *str) int i,n=0,fg=1;char *p=str;while (*p) n+; p+;for (i=0;i #include long fun ( char *p) long s=0,t;int i=0,j,n=str

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 社会民生

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号