




已阅读5页,还剩26页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
北方民族大学课程 设计 课程名称: 高 级 语 言 程 序 设 计 院(部)名 称: 信息与计算科学学院 组长姓名学号:马永强20100698 同组人员姓名:单新宇 刘靠兵 黄瑞荣指导教师姓名: 常 霞 设 计 时 间: 2011.6.7-2011.6.30 /*6.从文件读入一个字符串,统计该字符串中单词的个数,单词之间用空格分开,空格数可以是多个。*/#includeint main(void)char str80;int i=0,n=0;printf(Please Input a string:);gets(str);doif(stri=a&stri=A&stri=a&stri=A&stri=Z);n+;i+;while(stri!=0);printf(%dn,n);return 0;/* 8.编写程序,输入一个以回车符结束的字符串,过滤去所有的非十六进制字符后,组成一个新的字符串,然后将其转换为十进制数输出。 */#include#include#includeint main(void)char ch80,fch80;int i=0,j=0,k=0;double result=0;printf(请输入字符串(回车符结束):);scanf(%s,ch);while(chi!=0)if(0=chi&chi=9)|(a=chi&chi=f)|(A=chi&chi=F)fchj+=chi+;elsei+;fchi=0;j=j-1;while(fchk!=0)if(0=fchk&fchk=9)result+=(fchk-0)*pow(16,j);putchar(fchk);k+;j-;else if(a=fchk&fchk=f)result+=(fchk-a+10)*pow(16,j);putchar(fchk);k+;j-;else if(A=chk&chk=F)result+=(chk-A+10)*pow(16,j);putchar(chk);k+;j-;elsek+;printf(的十进制是:%.0fn,result);return 0;/*9.输出100-2000之间的所有素数,每行输出8个。要求调用求素数函数。*/#includeint pr(int n);int main(void)int n,count=0;for(n=100;n=2000;n+)if(pr(n)=1)printf(%6d,n);count+;if(count%8=0)printf(n);printf(n);return 0;int pr(int n)int i;for(i=2;i=n/2;i+)if(n%i=0)return 0;return 1;/*10.验证哥德巴赫猜想:任何一个大于6的偶数可以表示为两个素数之和。要求,每个偶数只要找到一组素数和就可以。将6-1000之间的所有偶数都表示程两个素数之和,每行输出5组显示。*/#includeint main(void) int i,j,k,m,count=0;for(i=6;i=1000;i+=2) for(j=2;ji;j+) for(k=2;k=j) m=i-j;for(k=2;k=m) printf(%4d=%4d+%4d ,i,j,m);count+;break;if(count=5)printf(n);return 0; /*11.编写一个求四则运算的运算器 */#includeint main(void)double y,v1,v2;int a,b;char o;printf(Type in an expression:);scanf(%lf%c%lf,&v1,&o,&v2);if(o=37)a=v1;b=v2;printf(%d%c%d%=%dn,a,o,b,a%b);else if(o=42)y=v1*v2;printf(%.2f%c%.2f%=%.2fn,v1,o,v2,y);else if(o=43)y=v1+v2;printf(%.2f%c%.2f%=%.2fn,v1,o,v2,y);else if(o=45)y=v1-v2;printf(%.2f%c%.2f%=%.2fn,v1,o,v2,y);else if(o=47)y=v1*1.0/v2;printf(%.2f%c%.2f%=%.2fn,v1,o,v2,y);elseprintf(输入有误!n);return 0; /* 13.编写程序要求实现给定一个年月日能够输出该日是这一年的第几天,给定这一年的第几天,要求能输出这一天是几月几日。 */#includeint main(void)int day,month,year,yearday;int n;void month_day(int year,int yearday,int *pmonth,int *pday);int which_day(int year,int month,int day);printf(1给定一个年月日能输出该日是这年的第几天!n2给定一年的第几天能输出这一天是几月几日!nInput your choice:);scanf(%d,&n);switch(n)case 1:printf(Input year and yearday:);scanf(%d%d,&year,&yearday);month_day(year,yearday,&month,&day);printf(%d-%d-%dn,year,month,day);break;case 2:printf(Input year-month-day:);scanf(%d%d%d,&year,&month,&day);printf(Today is:%d %d,year,which_day(year,month,day);break;default:printf(Unknown choicen);break;return 0;void month_day(int year,int yearday,int *pmonth,int *pday)int k,leap;int tab213=0,31,28,31,30,31,30,31,31,30,31,30,31,0,31,29,31,30,31,30,31,31,30,31,30,31,;leap=(year%4=0&year%100!=0)|year%400=0;for(k=1;yeardaytableapk;k+)yearday-=tableapk;*pmonth=k;*pday=yearday;int which_day(int year,int month,int day)int k,leap,sum=0;int tab213=0,31,28,31,30,31,30,31,31,30,31,30,31,0,31,29,31,30,31,30,31,31,30,31,30,31,;leap=(year%4=0&year%100!=0)|year%400=0;for(k=1;kmonth;k+)sum+=tableapk;sum=sum+day;return sum;/*14.建立n阶螺旋方阵*/#includeint main(void)int a8080,i,j,k=1,n,x=0,b,c,d;printf(Input n:);scanf(%d,&n);if(n%2=0)d=n/2-1;if(n%2!=0)d=n/2; for(b=0,c=0;b=d,c=d;b+,c+)for(j=c;jn-x;j+)abj=k;k+;for(i=b+1;i=c;j-)an-(x+1)j=k;k+;for(i=n-(x+2);ib;i-)aic=k;k+;x+; for(i=0;in;i+)for(j=0;jn;j+)printf(%6d,aij);printf(n);printf(n);return 0;/*18.编写程序,分别输出上三角形式和下三角式的乘法九九表*/#includeint main(void)void f(int n);void g(int n);g(9);putchar(n);f(9);return 0;void f(int n)int i,j;for(i=1;i=n;i+)for(j=1;j=i;j+)printf( );for(j=i;j=n;j+)printf(%4d,i*j);putchar(n);void g(int n)int i,j;for(i=1;i=n;i+)for(j=1;j=n-i;j+)printf( );for(j=n-i+1;j=n;j+)printf(%4d,j*(n-i+1);putchar(n);/*20.打印杨辉三角(要求:打印出两种形式)*/#includeint main(void)int n,i,j,a8080;printf(Enter n:);scanf(%d,&n);for(i=0;in;i+)ai0=1;aii=1;for(i=2;in;i+)for(j=1;ji;j+)aij=ai-1j-1+ai-1j;printf(%dn,a00);for(i=2;in;i+)for(j=0;j=i;j+)printf(%1d ,aij);printf(n);if(i=1)for(j=0;jn-i;j+)printf( );printf( %dn,a00);for(i=2;in;i+)for(j=0;jn-i;j+)printf( );for(j=0;j=i;j+)printf(%1d ,aij);printf(n);/*22.用递归法实现一个正整数的逆序输出。*/#includevoid yd(int n);int main(void) int n; printf(Enter a enterge :n); scanf(%d,&n); yd(n);void yd(int n) printf(%d,n%10); n=n/10; if(n!=0) yd(n);/*23.输入一个长整形数,从高位开始逐位分割并输出。如输入123456,逐位输出1,2,3,4,5,6.*/ #include#includeint main(void)int n,i=0,j,k,z;printf(Input n:);scanf(%d,&n);k=n;/*先来统计它的位数*/while(k=10)k=k/10;i+;/*逐位输出*/while(i=0)z=pow(10,i);j=n/z;n=n-j*pow(10,i);printf(%d ,j);i-;printf(n);return 0;/*30.编写程序,从键盘输入3个学生的数据,将它们存入文件student;然后再从文件中读出数据,显示在屏幕上。*/#include #include#define SIZE 3struct student long num;char name10;int age;char address10; stuSIZE, out;void fsave ( ) FILE *fp;int i;if(fp=fopen(student, wb)= NULL) printf(Cannot open file.n); exit(1); for(i=0;iSIZE;i+) if(fwrite(&stui,sizeof(struct student),1,fp) != 1 )printf(File write error.n); fclose(fp); main() FILE *fp;int i;for(i=0;iSIZE;i+) printf(Input student %d:,i+1);scanf(%ld%s%d%s,&stui.num,,&stui.age,stui.address);fsave(); fp = fopen(student,rb); printf( No. Name Age Addressn);while(fread(&out,sizeof(out),1,fp) printf (%8ld %-10s %4d %-10sn, out.num,,out.age,out.address);fclose(fp); /*T3.学生信息管理系统设计学生信息包括:学号,姓名,年龄,性别,出生年月,地址,电话,E-mail等。试设计一学生信息管理系统,使之能提供以下功能:系统以菜单方式工作学生信息录入功能(学生信息用文件保存)-输入学生信息浏览功能-输出查询、排序功能-算法按学号查询按姓名查询学生信息的删除与修改(可选项)#include#include#includestruct studentchar name20;long id;int age;char sex4;char birthday30;char where50;char telephone20;char email30;void new_student();void out_put_list();void view();void new_flist();int main(void)int choice;doprintf(功能选项:1-新建!2-浏览!3-查询!4-排序!0-退出!nPlease Enter your choice:);scanf(%d,&choice);switch(choice)case 1:new_student();break;case 2:out_put_list();break;case 3:view();break;case 4:new_flist();break;case 0:break;default:printf(Error input,please input again!n);main();break;while(choice!=0);printf(Thanks for your using!n);return 0;void new_student()FILE *fp;int i=0,j,n;static struct student stu80;printf(Please input recorders of n:);scanf(%d,&n);if(fp=fopen(ff.txt,w)=NULL)printf(File open error!n);exit(0);printf(Please input:n id name age sex birthday address telephone emailn);while(in) scanf(%ld%s%d%s%s%s%s%s,&stui.id,,&stui.age,stui.sex,stui.birthday,stui.where,stui.telephone,stui.email);i+;for(j=0;ji;j+)fprintf(fp,%ld %s %d %s %s %s %s %sn,stuj.id,,stuj.age,stuj.sex,stuj.birthday,stuj.where,stuj.telephone,stuj.email);for(j=0;ji;j+) printf(%ld %s %d %s %s %s %s %sn,stuj.id,,stuj.age,stuj.sex,stuj.birthday,stuj.where,stuj.telephone,stuj.email);if(fclose(fp)printf(Can not close the file!n);exit(0);void out_put_list()int i=0,j=0,choice,fn,nn;FILE *fp;static struct student stu80;printf(Please input from-number and n-number:);scanf(%d%d,&fn,&nn);if(fp=fopen(ff.txt,r)=NULL)printf(File open error!n);exit(0);while(!feof(fp)fscanf(fp,%ld%s%d%s%s%s%s%s,&stui.id,,&stui.age,stui.sex,stui.birthday,stui.where,stui.telephone,stui.email);i+;for(i=fn-1;ifn+nn-1;i+)printf(编号:%ld 姓名:%s 年龄:%d 性别:%s 出生日期:%sn,stui.id,,stui.age,stui.sex,stui.birthday);printf(Press 1 for detail,Press 2 return to main,Press 3 to view again,Press otherkey to break!nPlease input your choice:);scanf(%d,&choice);switch(choice)case 1:for(j=1,i=fn-1;ifn+nn-1;i+)printf(第%d条记录: 编号:%ld 姓名:%s 年龄:%d 性别:%s 出生日期:%s 地址:%s 电话号码:%s Email:%s n,j+,stui.id,,stui.age,stui.sex,stui.birthday,stui.where,stui.telephone,stui.email);break;case 2:main();break;case 3:out_put_list();break;default:printf(输入有误n);break;if(fclose(fp)printf(Can not close the file!n);exit(0);void view() FILE *fp;int i=1,j,choice,num;char tmp20;char *p;p=tmp;struct student stu7;if(fp=fopen(ff.txt,r)=NULL)printf(File open error!n);exit(0);while(!feof(fp)fscanf(fp,%ld%s%d%s%s%s%s%s,&stui.id,,&stui.age,stui.sex,stui.birthday,stui.where,stui.telephone,stui.email);i+;printf(1:姓名 2:编号nPlease input your choice:);scanf(%d,&choice); switch(choice)case 1:printf(请输入姓名:);scanf(%s,tmp);for(j=1;ji;j+)if(strcmp(p,)=0) printf(编号:%ld 姓名:%s 年龄:%d 性别:%s 出生日期:%s 地址:%s 电话号码:%s Email:%s n,stuj.id,,stuj.age,stuj.sex,stuj.birthday,stuj.where,stuj.telephone,stuj.email);break; case 2:printf(请输入编号:);scanf(%ld,&num);for(j=1;ji;j+)if(stuj.id=num) printf(编号:%ld 姓名:%s 年龄:%d 性别:%s 出生日期:%s 地址:%s 电话号码:%s Email:%s n,stuj.id,,stuj.age,stuj.sex,stuj.birthday,stuj.where,stuj.telephone,stuj.email);break;default :printf(Error input!n);break; if(fclose(fp) printf(Can not close the file!n); exit(0);void new_flist()int i=0,j,k,style,index,count;FILE *fp;static struct student stu80;struct student temp;if(fp=fopen(ff.txt,r)=NULL)printf(File open error!n);exit(0);wh
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025版新能源项目合作商业秘密保护协议范本
- 农村教育质量提升报告:2025年资源配置优化与公平性实践
- 220kV输变电工程关键施工技术与策略
- 2025年影视工业化制作流程优化与质量控制技术创新报告
- 大数据交易中心项目合作意向书
- 直播电商主播影响力与直播电商营销策略创新与实践案例深度解析与数据分析应用研究报告
- 重难点自考专业(小学教育)真题附答案【典型题】
- 医疗器械行业国产化替代中的企业核心竞争力培养与提升研究报告
- 2025年医药行业CRO模式下的临床试验设计与统计分析报告
- 专升本复习提分资料【典型题】附答案详解
- 美术介绍教学课件
- 2025年福建省福州左海供应链集团有限公司招聘笔试参考题库含答案解析
- 2025届上海市中考语文真题作文题目解析+范文
- 素描构图与透视教案
- 体育培训入股协议书
- 2025年职工技能大赛考核试题及答案
- 仓库运输管理方案计划
- 2025年“铸牢中华民族共同体意识”应知应会知识竞赛题库试卷及答案
- 云计算环境下的数据安全与隐私保护研究
- 传媒入股协议合同
- 《高效能电机》课件
评论
0/150
提交评论