ImageVerifierCode 换一换
格式:DOCX , 页数:49 ,大小:49.16KB ,
资源ID:24268109      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/24268109.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(西电计算机考研机试代码.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

西电计算机考研机试代码.docx

1、西电计算机考研机试代码王道论坛()友情分享!08 Problem A#include void main()int isarithmetic(int array,int n);void bubble(int array,int n);int num,m,i=0,array1100,array21001000;scanf(%d,&num);while(num0)int j;array1i=num;for(j=0;jnum;j+)scanf(%d,&array2ij);i+;scanf(%d,&num);for(m=0;mi;m+)bubble(array2m,array1m);if(isarit

2、hmetic(array2m,array1m)printf(yesn);elseprintf(non);int isarithmetic(int array,int n)int i,differ;differ=array0-array1;for(i=1;in-1;i+)if(differ!=arrayi-arrayi+1)return 0;return 1;void bubble(int array,int n)int i,j,temp;予人玫瑰手留余香王道论坛王道论坛()友情分享!予人玫瑰手留余香for(i=0;in-1;i+)for(j=0;jarrayj+1)temp=arrayj;ar

3、rayj=arrayj+1;arrayj+1=temp;08 Problem B#include void main()int i=0,m,array100;scanf(%d,&array0);while(arrayi+)scanf(%d,&arrayi);for(m=0;m99 & arraym1000)int digit,ten,hunder;hunder=arraym/100;ten=arraym%100/10;digit=arraym%10;if(arraym=hunder*hunder*hunder+ten*ten*ten+digit*digit*digit)printf(yesn)

4、;elseprintf(non);elseprintf(non);08 Problem C#include void main()王道论坛王道论坛()友情分享!int circle(int scalar);int n,i,number=0,array10;scanf(%d,&n);while(n)arraynumber+=n;scanf(%d,&n);for(i=0;i2 & t=scalar*scalar/2)return t;elsereturn 0;08 Problem D#include #include void main()int prime(int n);int sum(int

5、n);int countprime(int n);int i,num,countsample=0,count=0,array100;scanf(%d,&num);予人玫瑰手留余香王道论坛王道论坛()友情分享!while(num) /输入各组整数以 0结束arraycountsample+=num;scanf(%d,&num);for(i=0;icountsample;i+)if(countprime(arrayi)=sum(arrayi)printf(yesn);elseprintf(non);int prime(int n) /判断一个整数是否是素数int p,i;p=(int)sqrt(n

6、);for(i=2;i=p;i+)if(n%i=0)return 0;return 1;int sum(int n) /求一个整数各位数字之和int i,count=0;for(i=1;n/i!=0;i=10*i)count+=n%(10*i)/i;return count;int countprime(int n) /求一个整数的质因数各位之和int i,count=0;if(prime(n)return sum(n);for(i=2;i=n;i+)if(prime(i) & n%i=0)count+=sum(i);n/=i;予人玫瑰手留余香王道论坛王道论坛()友情分享!i=1;return

7、 count;08 Problem E#include#include#include/利用数组计算void jisuan(char a, int n)予人玫瑰手留余香int result1001 = 0;int i = 0;int j = 0;int flag = 0;int Len, dLen;int inta, temp1;int temp2;int lastlen;/结果的记录/用于记录整数的位置/标志号/分别用于记录去掉小数点后,总长度与小数点的长度/用于存储数值与辅助值/辅助值 2/确认最后小数的数组长度int p, q;/找到小数点的位置while (ai)if (ai != .

8、 & !flag)j+;/找到小数点,并且将小数点这一位开始,数值向前移动一位elseif (!flag)i+;flag = 1;continue;elseai - 1 = ai;王道论坛王道论坛()友情分享!i+;予人玫瑰手留余香Len = strlen(a);dLen = Len - j - 1;if (dLen 0) /将整形数值以数值的形式转化给数组result1000 - i = temp1 % 10;temp1 = temp1 / 10;i+;/开始计算,关键代码在于此:/分数与分数之间的相乘,用一个固定值分别与数组中的每一个数值相乘temp2 = n;while (temp2 !

9、= 1)for (i = 1000; i 0; i-)resulti = resulti * inta;for(i = 1000; i 0; i-)if (resulti / 10 != 0)resulti - 1 = resulti - 1 + resulti / 10;resulti = resulti % 10;王道论坛王道论坛()友情分享!temp2-;/打印予人玫瑰手留余香lastlen = dLen * n;/确认最后小数的数组长度/解决前后 0的情况,并将前后不为 0的情况记录 p、qfor (p = 1; p 1000)printf(0);return;for (q = 100

10、0; q = 1 & resultq = 0; q-);if (1000 - p + 1 = lastlen) /考虑到 0.几的情况问题printf(.);for (i = 1000 - lastlen + 1; i= lastlen) /考虑没有小数的情况for (i = p; i = 1000 - lastlen; i+)printf(%d, resulti);printf(n);else /正常的情况for (i = p; i = 1000 - lastlen; i+)王道论坛王道论坛()友情分享!printf(%d, resulti);printf(.);for (i = 1000

11、- lastlen + 1; i = q; i+)printf(%d, resulti);printf(n);int main()char s7;int n;while (scanf(%s%d, s, &n) != EOF)jisuan(s, n);return 0;09 Problem A#include int main()int perfect(long n);long a,b,i;scanf(%ld %ld,&a,&b);for(i=a;i=b;i+)if(perfect(i)printf(%ldn,i);return 0;int perfect(long n)long i,count

12、=0;for(i=1;in;i+)予人玫瑰手留余香王道论坛王道论坛()友情分享!if(n%i=0)count+=i;if(count=n)return 1;elsereturn 0;09Problem B#include int main()void sort(int array,int n);int i,j,num,p=0,array99,result20;scanf(%d,&num);for(i=0;i20;i+)resulti=0; /输出数组赋初值 0for(i=0;inum;i+)for(j=0;jnum;j+)scanf(%d,*(array+i)+j);for(i=0;inum;

13、i+) /每行元素和for(j=0;jnum;j+)resultp+=*(*(array+i)+j);p+;for(j=0;jnum;j+) /每列元素和for(i=0;inum;i+)resultp+=*(*(array+i)+j);p+;for(i=0;inum;i+) /对角线元素和resultp+=*(*(array+i)+i);p+;予人玫瑰手留余香for(i=0;inum;i+)/对角线元素和resultp+=*(*(array+i)+3-i);sort(result,2*num+2);for(i=0;i2*num+2;i+)printf(%d ,resulti);printf(n

14、);return 0;王道论坛王道论坛()友情分享!void sort(int array,int n) /冒泡排序int i,j,temp,no;for(i=0;in-1;i+)no=0;for(j=0;jn-i-1;j+)if(arrayjarrayj+1)temp=arrayj;arrayj=arrayj+1;arrayj+1=temp;no=1;if(no=0)break;09 Problem C#include #include int main()unsigned int getwholenum(char *array);int factor(unsigned int n);int

15、 num,i;char array100;unsigned int wholenum;scanf(%d,&num);for(i=1;i=0 & *(array+i)=9)resultarrayj+=*(array+i);i+;*(array+i)=0;return strtoul(resultarray,0,10);int factor(unsigned int n)int i,result;for(i=1;i(int)n;i+)if(n%i=0)result=i;if(result=1)result=n;return result;09 Problem D#include #include

16、#include #define NULL 0struct btreechar num;struct btree *lchild;struct btree *rchild;struct stackstruct btree *base;struct btree *top;予人玫瑰手留余香王道论坛王道论坛()友情分享!予人玫瑰手留余香int satcksize;int main()struct btree *create(char *arrayfirst,char *arraymiddle,int len);void followvisit(struct btree *bt);char array

17、first20,arraymiddle20;int len;struct btree *bt;scanf(%sn%s,arrayfirst,arraymiddle);len=strlen(arrayfirst);bt=create(arrayfirst,arraymiddle,len);followvisit(bt);printf(n);return 0;struct btree *create(char *arrayfirst,char *arraymiddle,int len) /建立二叉树struct btree *bt;bt=(struct btree *)malloc(sizeof(

18、struct btree);if(len=1)bt-num=*arrayfirst;bt-lchild=NULL;bt-rchild=NULL;return bt;elseint count=1,i=0;while(*arrayfirst!=*(arraymiddle+i)i+;count+;bt-num=*arrayfirst;if(count=1)bt-lchild = 0;elsebt-lchild=create(arrayfirst+1,arraymiddle,count-1);if(count=len)bt-rchild = 0;elsebt-rchild=create(arrayf

19、irst+count,arraymiddle+count,len-count);王道论坛王道论坛()友情分享!予人玫瑰手留余香return bt;void followvisit(struct btree *bt) /后续遍历二叉树(递归)if(!bt-lchild & !bt-rchild)printf(%c,bt-num);elseif(bt-lchild)followvisit(bt-lchild);if(bt-rchild)followvisit(bt-rchild);printf(%c,bt-num);/*void followvisit(struct btree *bt)struc

20、t btree *p,array20;int top=0;p=bt;while(top=0 | *p)if(*p)arraytop+=*p;p=p-lchild;elsep=&array-top;if(!p-rchild)printf(%c,p-num);top-;p=arrayelsetop+;p=p-rchild;王道论坛王道论坛()友情分享!予人玫瑰手留余香*/09 Problem E#include int main()int num,i,j,top;char array100,stack100;scanf(%dn,&num);for(i=0;i=2)if(stacktop-2=( & stacktop-1=) | (stacktop-2= &stacktop-1=) | (stacktop-2= & stacktop-1=)top-=2;j+;if(top=0)printf(yesn);elseprintf(non);return

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1