首页 数据结构作业

数据结构作业

举报
开通vip

数据结构作业作业一: 2-28留3-7日交 写出以下程序的功能: 1.#include void fun(long s, long *t) { long w = 10; s /=10; *t = s%10; while(s>0) { s = s/100; *t = s%10 * w + *t; w = w*10; } } main() { long s, t; printf(“\n Please enter s:”); scanf(“%ld”,&s); fun(s,&t); prin...

数据结构作业
作业一: 2-28留3-7日交 写出以下程序的功能: 1.#include void fun(long s, long *t) { long w = 10; s /=10; *t = s%10; while(s>0) { s = s/100; *t = s%10 * w + *t; w = w*10; } } main() { long s, t; printf(“\n Please enter s:”); scanf(“%ld”,&s); fun(s,&t); printf(“The result is: %ld\n”,t); } 注:若输入s的值为:7654321,则输出t的值为642. 2.#include #define N 16 typedef struct { char num[10]; int s; }STREC; void funt(STREC a[N]) { int i, j; STREC t; for(i = 0; i < N; i++) for(j = i; j < N; j++) if(a[i].s < a[j].s) { t = a[i]; a[i]=a[j]; a[j] = t; } } main() { STREC a[N] = {{“GA005”,85},{“GA003”,76},{“GA002”,69},{“GA004”,85}, {“GA001”,91},{“GA007”,72},{“GA008”,64},{“GA006”,87}, {“GA0015”,87},{“GA0013”,92},{“GA0012”,65},{“GA0014”,92}, {“GA0011”,88},{“GA0017”,78},{“GA0018”,60},{“GA0016”,95}}; int i; fun(a); for(i =0;i #include #define M 81 int fun(char *ss, char c) { int i,num = 0; for(i=0;ss[i] !=’\0’;i++) if(ss[i] == c) num++; return num; } main() { char a[M], ch; printf(“\n Please enter a string:”); gets(a); printf(“\n Please enter a char:”); ch = getchar(); printf(“\n The number of the char is: %d \n”, fun(a,ch)); } 注:若输入a的值为:Happy New year,的值为:y,则输出结果为:2 4.#include #define N 8 typedef struct { char num[10]; double s; }STREC; double fun(STREC *a, STREC *b, int *n) { double sum = 0; int i,j=0; *n = 0; for(i =0;i #include #include #define N 9 long ctod(char *s) { long d = 0; while(*s) if(isdigit(*s)) { d = d *10 +*s - ; ; } return d; } long fun(char *a, char *b) { return ; } main() { char s1[N],s2[N]; do { printf(“Input sting s1:”); gets(s1); } while(strlen(s1)>N); do { printf(“Input sting s2:”); gets(s2); } while(strlen(s2)>N); } 2、给定程度中,函数fun的功能是:判断形参s所指字符串是否是“回文”,若是,函数值 返回1;不是,函数返回值为0。“回文”是正读和反读都一样的字符串,不区分大小写。 例如:LEVEL和Level都是“回文”,而LEVLEV不是“回文”。 #include #include #include int fun(char *s) { char *lp,*rp; lp = ; rp = s + strlen(s) -1; while( toupper(*lp) == toupper(*rp) && lp #define N 4 void fun(int ,int n) { int i,s; for( ;i++) { s = t[i][i]; t[i][i] = ; =s; } main() { int t[][N] = {21,12,13,24,25,16,47,38,29,11,32,54,42,21,33,10},i,j; printf(“\n The original array:\n”); for(i = 0; i
本文档为【数据结构作业】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_882336
暂无简介~
格式:doc
大小:27KB
软件:Word
页数:0
分类:
上传时间:2019-09-05
浏览量:18