一已知数组A中有max个整数资料.ppt

  1. 1、本文档共12页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
一已知数组A中有max个整数资料

MEUE About the question Thought of design Achieve the algorithm Analyze the algorithm Summary About the QuestionⅠ 一.已知数组A中有max个整数,编程实现将其每个数组元素的值除以3,得到的余数或为0,或为1,或为2,按此三种不同的情况,将原数组分解为三部分,分别存放在数组 B、C 和 D中; 要求在该程序中编写下列两个子程序: 1. 从键盘接收max个整数存放于给定的数组中; 2. 输出打印给定的数组中的有效数据。 * Thought of design 首先定义两个函数 和 ,用来执行输入数据和输出数据的作用,并在其中设置结束输出的条件,然后建立四个数组,一个原数组,三个新数组用来存储数据,再建立一个switch语句作为判断选择,把除3余0、1、2的数值放如上面三个数组中,最后形成main函数。 Achieve the algorithm * define max 20 void Output(int a[]) { int i; for (i=0;imaxa[i]!=0; i++) { printf (%3d ,a[i]); if(i%5==4) printf(\n); } } void Input(int a[]) { int i; for(i=0;imaxa[i]!=#;i++) scanf(%d,a[i]); } void depart(int a[],int b[],int c[],int d[]) { int g; int i=0; int j=0; int k=0; int x=0; * for (i = 0; i max; i++) { g=a[i]%3; switch (g) { case 0: b[j] = a[i];j++; break; case 1: c[k] = a[i];k++; break; case 2: d[x] = a[i];x++; break; default: printf (error \n); } } } void main () { int a[20]={0}; int b[20]={0}; int c[20]={0}; int d[20]={0}; * printf(\nEnter the Array:\n); Input(a); depart(a,b,c,d); printf (\nthe numbers a[] is: \n); Output(a); printf (\nthe numbers b[] is: \n); Output(b); printf (\nthe numbers c[] is: \n); Output(c); printf (\nthe numbers d[] is: \n); Output(d); } * About the QuestionⅡ 已知一个链表A的长度为50,将其每个数据元素的值除以3,得到的余数或为0,或为1,或为2,按此三种不同的情况,将原链表分解为三部分,分别存放在链表B,C 和 D中。 Analyze the algorithm(简) 根据所学链表和题目意图可以用函数实 现链表的初始化和显示链表中的数据。 * Achieve the algorithm #includemalloc.h #define NULL 0 typedef int ElemType; typedef struct LNode{ ElemType data; struct LNode *next; }LNode,*LinkList; void CreateList_L(LinkList *L,int n) { LinkList p; int i; *L=(LinkList)malloc(sizeof(LNode)); (*L)-next=NULL; for(i=n;i0;--i) * { p=(LinkList)malloc(sizeof(LNode)); scanf(%d,p-data); p-next=(*L)-next; (*L)-next=p;

文档评论(0)

aena45 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档