三九宝宝网宝宝教育教学论文

c语言离散数学集合复合运算的代码 R

01月04日 编辑 39baobao.com

[汇编语言算术运算指令]简单写了个两数相加的。 dseg segment num1 db 27H num2 db 45H dseg ends cseg segment assume cs:cseg,ds:dseg begin: mov ax,dseg mov ds,ax mov al,num1 add al,num2 d...+阅读

//说明:输入的格式需要提示按输入,因为要获取正确的有序对才能进行复合运算/**************输入格式如:a b, #,# 退出*************** 输入:a b 输入:b t 输入:t d 输入:s j 输入:j i 输入:c a*/#include "stdlib.h" typedef char Element; struct Node { Element left; Element right; struct Node *next; }; struct Node *CreateLink(); struct Node *Operation(struct Node *R,struct Node *S); void PrintLink(struct Node *h); int main() { struct Node *hdR,*hdS,*rhd; printf("请输入第一个集合R的关系\n"); hdR = CreateLink(); PrintLink(hdR); printf("\n请输入第二个集合S的关系\n"); hdS = CreateLink(); PrintLink(hdS); rhd = Operation(hdR,hdS); if (rhd->next == NULL) { printf("\nR。

S结果为空集\n"); } else { printf("\nR。S结果为:\n"); PrintLink(rhd); } return 0; } struct Node *CreateLink() { struct Node *head, *p; printf("*************输入格式如:a b, \'#,#\' 退出***************\n"); Element a,b; head = (struct Node *)malloc(sizeof(struct Node)); head->left = 0; head->right = 0; head->next = NULL; printf("输入:"); scanf("%c %c",&a,&b); getchar(); while (a != '#') { p = (struct Node *)malloc(sizeof(struct Node)); p->left = a; p->right = b; p->next = head->next; head->next = p; printf("输入:"); scanf("%c %c",&a,&b); getchar(); } return head; } struct Node *Operation(struct Node *R, struct Node *S) { struct Node *newHead,*newP,*newQ; struct Node *pH, *pNext; newHead = (struct Node *)malloc(sizeof(struct Node)); newHead->left = 0; newHead->right = 0; newHead->next = NULL; newP = newHead; if (R->next == NULL || S->next == NULL) { return newP; } char cLeft,cRight; pH = R; while (pH->next != NULL) { cLeft = pH->next->left; cRight = pH->next->right; pNext = S->next; while(pNext != NULL) {//存在可以复合运算的 if (cRight == pNext->left) {//在复合运算结果集中插入数据,如果存在相同的二元关系,则不需要插入 newP = newHead; while (newP->next != NULL) { if (cLeft == newP->left & cRight == newP->right) { break; } newP = newP->next; } if (newP->next == NULL) { newQ = (struct Node *)malloc(sizeof(struct Node)); newQ->left = cLeft; newQ->right = pNext->right; newQ->next = NULL; newP->next = newQ;// newQ->next = newP->next->next; } } pNext = pNext->next; } pH = pH->next; } return newHead; } void PrintLink(struct Node *h) { struct Node *p=h->next; printf("\n"); while (p != NULL) { printf("",p->left,p->right); p = p->next; } printf("\n"); }

以下为关联文档:

C语言运算符和scanf函数(1) strcmp函数的原型是: int strcmp(char *p1,char *p2) {int i=0; while (*(p1+i)==*(p2+i)) if (*(p1+i++)=='\0') return 0;/* 这里是先判断*(p1+i)=='\0',然后再是i++ */ re...

C语言编写5个函数加减乘除取余运算#include<stdio.h> double jia(double a,double b){ return a+b;} double jian(double a,double b){ return a-b;} double cheng(double a,double b){ return a*b;} double...

在c语言中什么是运算哦,这个问题很简单,你说的这个英文中叫operand,一般翻译为操作数。和它一起出现的是operator,一般翻译为操作符。举个例子: int a, b = 3, c = 6; a = b * c; 在上面的语句中,b和c...

易语言写出Excel的运算功能代码如下: .版本 2 .子程序 计算表达式, 文本型, 公开, 计算表达式,失败返回空 .参数 数学表达式, 文本型, , 支持数学函数 例如 Math.pow(2,3) .局部变量 JavaScript, 对象 JavaScri...

汇编语言定义字节类型变量xyz编程实现四则运算2 xyz;定义字节类型变量xyz,编程实现四则运算(2+x-y)/z,把运算结果存入字节类型变量f中 DATAS SEGMENT x db 22 y db 7 z db 3 f db ? DATAS ENDS STACKS SEGMENT dw 10 dup(0) STACKS...

C语言乘方运算C语言的乘方运算可以利用库函数pow。 pow函数原型:double pow( double x, double y ); 头文件:math.h/cmath(C++中) 功能:计算x的y次幂。 参考代码: #include <stdio.h> #includ...

C语言集合运算Deletetable函数有两个地方把pcollelm写成了collelm Addition函数体第4行没加分号 Addition函数中3次调用AppendToTable时都写了3个参数,但AppendToTable只声明了2个参数 Mul...

C语言定义一个函数实现两个集合的相加运算#include #include #include #define N 7 typedef enum { add, nul, sub, div1, yu, l, r }OP; int a[N][N] = { { 0, 0, -1, -1, -1, 1, 2 }, { 0, 0, -1, -1, -1, 1, 2 },...

集合的基本运算急!1.A解一元二次方程得A={-4,2},B解出来={2,3} 由于B交C不为空,所以C中至少有2,3中的一个作为元素 又如果C有元素2,那么C交A就不为空,所以C一定没有元素2,所以C有元素3 将3带入,得9...

推荐阅读
图文推荐