C语言上机考试题—011.//#include <conio.h>#include <stdio.h>double fun( int n ){double sum=0,a=1;for(;n>0;n--,a++)sum=sum+1/(a*(a+1));return sum;}main(){// clrscr();printf("%f\n", fun(10));}2. #include <stdio.h>main(){int k,m,s=0,i,b=0;for(k=10000;k<=20000;k++ ){if(k%10==7){for(i=2,b=0;i<k;i++)if(k%i==0)b++;if(b==0)m=k,s++;}}printf("这样的素数有%d 个。
\n其中最大的一个是%d\n",s,m);}3. #include <stdio.h>main() {int a;printf("请输入一个需要判断的年份:\n");scanf("%d",&a);if(a%4==0&&a%100!=0)printf("是闰年\n");elseif(a%400==0)printf("是闰年\n");elseprintf("不是闰年\n");}C语言上机考试题—021. //#include <conio.h>#include <stdio.h>double fun( int n ){double sum=0,a=1;for(;n>0;n--,a++)sum=sum+1/(a*(a+1));return sum;}main(){// clrscr();printf("%f\n", fun(10));}2.#include <stdio.h>fun(int n){int i,j=0;for(i=2;i<n;i++)if(n%i==0)j++;return j;}main(){int a,b=0,d,e,k;for(k=1;k<10;k++)if(fun(k)==0)a=k,b++;for(k=10;k<100;k++)if(fun(k)==0){e=k%10,d=k/10;if(e==d)a=k,b++;}for(k=100;k<=1000;k++)if(fun(k)==0){e=k%10,d=k/100;if(e==d)a=k,b++;}printf("[1,1000]之内既是回文数,又是素数的最大整数:%d\n",a);printf("[1,1000]以内既是回文数,又是素数的整数有%d个\n",b);}3.#include <stdio.h>#include <string.h>main(){char str[81];int i,j=0,w=1,s=0;printf("请输入一串字符:\n");gets(str);for(i=0;i<strlen(str);i++){if(str[i]==' ')s++;if(str[i]==''&&str[i+1]!=' ')w++;}if(str[0]==' ')w--;if(str[strlen(str)-1]==' ')w--;printf("单词个数为:%d\n 空格个数为:%d\n",w,s);}C语言上机考试题—031. //#include "conio.h"#include "math.h"#include "stdio.h"int fun(int t){int a=0,b=1,c,k;for(k=1;;k++){c=b;b=a+b;a=c;if(a>t)break;}return a;}main(){int n;//clrscr();n=1000;printf("n = %d, f = %d\n",n, fun(n));}2.#include "stdio.h"main(){int a[3][3],i,j,s=0;printf("请依次输入一个3*3矩阵:\n");for(i=0;i<3;i++)for(j=0;j<3;j++){scanf("%d",&a[i][j]);if(i==j||i+j==2)s=s+a[i][j]*a[i][j];}printf("对角线平方和为:%d\n",s);}3. #include<stdio.h>#include<string.h>#define N 81fun(char str[]){int i=0,j;while(i<N){if(str[i]<=57&&str[i]>=48)for(j=i;j<N;j++)str[j]=str[j+1];elsei++;}puts(str);}main(){char str[N];printf("请随意输入字符:");gets(str);fun(str);}C语言上机考试题—041. //#include "conio.h"#include "math.h"#include "stdio.h"double fun( int n){double s=0;int i;for(i=1;i<n;i++)if(i%21==0)s+=i;return sqrt(s);}main(){// clrscr();printf("s=%f\n", fun(1000) );}2. #include "stdio.h"main(){int a,b,k;for(;;){printf("请输入两数:\n");scanf("%d%d",&a,&b);if(a>0&&b>0)for(k=a;k>=1;k--)if(a%k==0&&b%k==0)break;if(a%k==0&&b%k==0)break;}printf("这两个数的最大公约数是:%d\n",k);}3.#include<stdio.h>main(){double a=1,b=1,i,j,s=0;for(i=1,j=3;;i++,j=j+2){a=a*i;b=b*j;s=s+a/b;if(a/b<0.00005)break;}printf("%f\n",2*(s+1));}C语言上机考试题—051.#include <conio.h>#include <stdio.h>int fun(int array[3][3]){int a[3][3],i,j;for(i=0;i<3;i++){for(j=0;j<3;j++)a[i][j]=array[j][i];}for(i=0;i<3;i++)for(j=0;j<3;j++)array[i][j]=a[i][j];return array[i][j];}main(){int i,j;intarray[3][3]={{100,200,300},{400 ,500,600},{700,800,900}};for(i=0;i<3;i++){for(j=0;j<3;j++)printf("%7d",array[i][j]);printf("\n");}fun(array);printf("converted array:\n");for(i=0;i<3;i++){for(j=0;j<3;j++)printf("%7d",array[i][j]);printf("\n");}}2.#include <stdio.h>main(){float x,y,s=0;int n;for(x=1;x<=100;x++){n=x;if(n%2==0)y=-1/x;elsey=1/x;s=s+y;}printf("前n项和为:%f\n",s);}3.#include<stdio.h>main(){int a[101]={0},i,n,s=0,t;for(n=2;n<=100;n++){for(t=0,i=2;i<n;i++){if(n%i==0)t++;}if(t==0)a[n]=n;}for(n=2;n<=100;n++)if(a[n]!=0&&a[n+2]!=0)s++;printf("2~100中的所有的亲密素数对的个数为:%4d\n",s);}C语言上机考试题—061.#include "stdio.h"main(){int a,b,c,s,k;printf("请输入一个大于2小于1000的数:\n");scanf("%d",&k);printf("它的所有质因子是:\n");for(a=2;a<=k;a++)if(k%a==0){for(s=0,b=2;b<a;b++)if(a%b==0)s++;if(s==0)printf("%5d",a);}printf("\n");}2. //#include "conio.h"#include "stdio.h"int fun (int n){int s=0,k;for(k=2;k<n;k++)if(n%k==0)s+=k;return s;}main(){//clrscr();printf("%d\n", fun (120)); }3.#include<stdio.h>main(){double a=1,b=1,i,j,s=0;int n;printf("请输入求和项数N:\n");scanf("%d",&n);for(i=1;i<=n;i++)s+=1/(i*(i+1));printf("数列前%d项求和为:%f\n",n,s);}C语言上机考试题--071.//#include <conio.h>#include <stdio.h>#include <math.h>double fun(double x , int n) {double a=1,c,s=0,i;c=x;for(i=1;i<=n+1;i++){a=a*i;s=x/a+s;x=x*c;}s=s+1;return s;}main(){//clrscr();printf("%f\n", fun(0.3,10)); }2. #include<stdio.h>main(){int a,b,c,d,k;for(k=100;k<=999;k++){a=k/100;b=(k-a*100)/10;c=k-a*100-b*10;d=a*a*a+b*b*b+c*c*c;if(k==d)printf("%5d",k);}printf("\n");}3. #include<stdio.h>#include<math.h>main(){float a,b,c,t,p;for(;;){printf("请正确输入三角形三边长:\n");scanf("%f%f%f",&a,&b,&c);if(a<b)t=a,a=b,b=t;if(b<c)t=b,b=c,c=t;if(a<b)t=a,a=b,b=t;if(a<b+c&&c>0)break;else continue;}p=(a+b+c)/2;t=sqrt(p*(p-a)*(p-b)*(p-c));printf("面积为:%f\n",t);}C语言上机考试题—081. //#include <conio.h>#include <stdio.h>#include <string.h>float fun(int n){int i,s=0;float p=0;for(i=1;i<=n;i++){s+=i;p+=1.0/s;}return p;}main(){int n;float s;// clrscr()printf("\nPlease enter N:");scanf("%d", &n);s = fun(n);printf("the result is: %f\n",s);}2. #include<stdio.h>main(){int i;float h=100,s=100;for(i=1;i<=10;i++){h=h/2;s+=h*2;}printf("第10次落地时,共经过:%f米\n",s);printf("第10次反弹的高度为:%f米\n",h);}3. #include<stdio.h>double fun(){double a=1,b=1,i,j,s=0;for(i=1,j=3;;i++,j=j+2){a=a*i;b=b*j;s=s+a/b;if(a/b<0.000001)break;}s=2*(s+1);return s;}main(){printf("%f\n",fun());}]C语言上机考试题—091. //#include "conio.h"#include "stdio.h"void fun( int m, int k ){int a,b,e=1,s=0;for(b=m;;){a=b%k;b=b/k;s+=a*e,e=e*10;if(b<k){s+=b*e;break;}}printf("该数为:%d\n",s); }main( ){int b,n;//clrscr();printf("\nPlease enter a number and a basen\n");scanf("%d%d",&n,&b);fun(n,b);printf("\n");}2. #include "stdio.h"main(){int a,b;for(a=1;a<10;a++){b=a*a;if(b%10==a)printf("%4d\n",a);}for(a=10;a<100;a++){b=a*a;if(b%100==a)printf("%4d\n",a);}for(a=100;a<=1000;a++){b=a*a;if(b%1000==a)printf("%4d\n",a);}}3. #include<stdio.h>main(){float f1,f2,f;f1=2*(-1)*(-1)+3*(-1)+4;f2=-2*5.0*5.0+3*5.0-4;if(f1+f2<=2)f=2*(f1+f2)*(f1+f2)+3*(f1+f2)+4;elsef=-2*(f1+f2)*(f1+f2)+3*(f1+f2)-4;printf("计算结果为:%f\n",f);}C语言上机考试题—101. //#include <conio.h>#include <stdio.h>long fun (int a, int n){long b,e,temp,t,k=1,sum=0;if(a<10&&a>0&&n>1&&n<10){temp=a;for(;k<=n;k++){for(b=0,e=1,t=1;t<=k;t++){a=temp;a=e*a;e=e*10;b+=-a;}sum+=b;}sum+=-2*b;return sum;}else printf("输入有的A或者N有问题求和结果不正确\n");}main( ){int a, n;//clrscr() ;printf("\nPlease enter a andn:\n ") ;scanf("%d%d",&a,&n) ;printf("The value offunction is: %1d\n",fun(a,n));}2. #include <stdio.h>fun(int n){int k,a=0;for(k=2;k<n;k++)if(n%k==0)a++;return a;}main(){int i,j,k,n,t,a,b;for(n=4;n<=100;n=n+2){for(i=2;i<n;i++){j=n-i;if(fun(i)==0&&fun(j)==0)break;}printf("%d=%d+%d\n",n,i,j) ;}}3. #include <stdio.h>main(){int k,l,m,s=0;for(k=0;k<=10;k++)for(l=0;l<=5;l++)for(m=0;m<=2;m++)if(100==k*10+l*20+m*50)s++;printf("共有%d种不同的兑换方法\n",s); }C语言上机考试题—111. //#include<conio.h>#include <stdio.h>double fun ( int x[ ]) {int a[1000];int i,j=0,k=0;double s=0;while(x[j]!='\0'){if(x[j]>0){a[k]=x[j];k++;}j++;}for(i=0;i<k;i++)s+=a[i];return s/k;}main( ){int x[1000]; int i=0;// clrscr();printf("\nPlease enter somedata (end with 0) ");do{scanf("%d",&x[i]);}while(x[i++] !=0);printf("%f\n",fun ( x ));}2. #include<stdio.h>#include<string.h>#define N 10main(){char str[N];int i=0,flag=0;long num=0;printf("请输入连续数字字符(最多10为数字) :");gets(str);while(str[i]!='\0'&&str[i]!='a'){if(str[i]=='-')flag=1;elseif(str[i]=='+')flag=0;elsenum=num*10+(str[i]-'0');i++;}if(flag==1)num=-num;printf("由数字字符串转化成整数是:%ld\n",num);}3. #include<stdio.h>main(){int a,b,c,s=0;for(a=0;a<=33;a++)for(b=0;b<=50;b++)for(c=0;c<=100;c=c+2)if(100==3*a+2*b+c/2&&a+b+c==100)s++;printf("共有驼法:%d种\n",s);}C语言上机考试题—121. //#include <conio.h>#include <stdio.h>float fun(int m, int n){float t,p,j,i,k,o;if(m<n)t=m,m=n,n=t;for(p=1,j=1,i=1,o=m;p<=m-n;o--,p++){j=o*j;i=p*i;}k=j/i;return k;}main() /*主函数*/{// clrscr();printf("P=%f\n", fun (12,8));}2.#include<stdio.h>main(){int x,y,z,i;printf("1到1000之内能被7或11整除、但不能同时被7和11整除的所有整数:\n");for(i=1;i<=1000;i++){x=i%7,y=i%11;if(x==0&&y!=0||y==0&&x! =0)printf("%4d",i);}printf("\n");}3.#include<stdio.h>main(){int a[3][3],i,j,sum=0;for (i=0;i<3;i++){for (j=0;j<3;j++)scanf("%d",&a[i][j]);}for (i=0;i<3;i++){for (j=0;j<3;j++){if(i+j==2||i==j)sum=sum+a[i][j];}}printf("%d",sum);}C语言上机考试题—131. #include <stdio.h>double fun(int n){double a=1,b=2,c,sum=0;for(;n>0;n--){sum=a/b+sum;c=a+b;a=b;b=c;}return sum;}main(){int n;printf("Enter n: ");scanf("%d", &n);printf("\nThe result : %f \n",fun(n));}2. #include <stdio.h>#include <string.h>main(){char str[81];int i,j=0,w=1,s=0;printf("请输入一串字符:\n");gets(str);for(i=0;i<strlen(str);i++){if(str[i]==' ')s++;if(str[i]==''&&str[i+1]!=' ')w++;}if(str[0]==' ')w--;if(str[strlen(str)-1]==' ')w--;printf("单词个数为:%d\n空格个数为:%d\n",w,s);}3. #include <stdio.h>main(){int k=1,sum=0;for(;k<200;k=k+2)sum=sum+k;printf("sum=%d\n",sum);}C语言上机考试题—141. //#include "conio.h"#include "stdio.h"#include "math.h"float fun(int n){float a=0,b=0,c=1,d,e,s=0,k;for(k=1;k<=n;k++){s+=sqrt(a);d=a+b+c;a=b,b=c;c=d;}return s;}main ( ){int n;//clrscr( );printf("Input N=");scanf("%d", &n);printf("%f\n", fun(n));}2 .#include<stdio.h>fun(int s[10]){int i,j;for(i=1;i<10;i++)for(j=0;j<10-i;j++)if(s[j]<s[j+1]){int temp;temp=s[j];s[j]=s[j+1];s[j+1]=temp;}printf("这10个数按从大到小排列为:\n");for(i=0;i<10;i++)printf("%d ",s[i]);}main(){int s[10],i=0;printf("请输入10个整数:");for(;i<10;i++)scanf("%d",&s[i]);fun(s);printf("\n");} 3. #include<stdio.h>fun(int s[10]){int i;float a=0;for(i=1;i<9;i++)if(s[i]>s[i+1]){int temp;temp=s[i];s[i]=s[i+1];s[i+1]=temp;}printf("这10个数中最大的为:%d\n",s[9]);for(i=0;i<10;i++)a+=s[i];printf("平均数为:%.1f",a/10);}main(){int s[10],i=0;printf("请输入10个整数:");for(;i<10;i++)scanf("%d",&s[i]);fun(s);printf("\n");}C语言上机考试题—151. //#include"conio.h"#include"stdio.h"double fun(int m){double a=1,b,j,s=0;for(j=1;j<=m;j++){a=a*j;b=1/a;s+=b;}return s;}main(){int n;//clrscr();printf("Enter n ");scanf("%d", &n);printf("\nThe resultis%1f\n", fun(n));}2. #include"stdio.h"main(){int a=1,j,s=0;for(j=1;j<=10;j++){a=a*j;s+=a;}printf("求和为:%d\n",s);}3. #include"stdio.h"main(){int a;for(;;){printf("请输入小孩年龄:\n");scanf("%d",&a);if(a<2||a>6){printf("不适合进入幼儿园,请检查年龄是否输错。