当前位置:网站首页>Realization of truth table assignment by discrete mathematical programming
Realization of truth table assignment by discrete mathematical programming
2022-06-24 21:09:00 【GS_ Qiang】
Code :
#include<stdio.h>
#include<math.h>
#define LEN 666 // Define array length
int arr[LEN]; // For storage 2^n Sub characters ,n Represents the number of variables
int brr[LEN][4+10]; //brr Used to store truth tables
int beg = 80; // character P Corresponding ASCII code
int sta1 = 0, sta2 = 0; //sta1 Indicates that the true value is 1 The number of ,sta2 Indicates that the true value is 0 The number of
int main()
{
int num; // Number of variables
printf(" Please enter the number of variables : ");
scanf("%d",&num);
int sum = pow(2, num); //2^n
printf(" Please enter %d A truth value ( With (p->q)->r For example ) : ",sum); // Input (p->q)->r The true value of , Examples can be changed freely
for(int i = 1; i <= sum; i++)
{
scanf("%d",&arr[i]);
if(arr[i] == 1)
sta1++; //sta1 Indicates that the true value is T The number of
else
sta2++; //sta2 Indicates that the true value is F The number of
}
printf("\n");
// Processing truth table
int cnt1 = 0, cnt2 = 1;
for(int i = sum-1; i >= 0; i--) // Binary implementation of the truth table assignment
{
cnt1 = 0;
int val=i;
while(cnt1 < num)
{
cnt1++;
brr[cnt2][cnt1] = val%2;
val = val/2;
}
cnt2++;
}
printf(" Output the truth table corresponding to the formula :\n");
for(int i = 1; i <= num ;i++)
{
printf("%c\t",beg++);
}
printf("(p->q)->r\n");
beg = 80;
for(int i = 1; i <= sum; i++)
{
for(int j = num; j >= 1; j--)
{
printf("%d\t",brr[i][j]);
}
printf("%d\n",arr[i]);
}
printf("\n");
int k = 0;
printf(" Output main disjunctive normal form :\n");
for(int i = 1; i <= sum; i++)
{
if(arr[i] == 1)
{
k++;
printf(" ( ");
for(int j = num; j >= 1; j--)
{
if(brr[i][j] == 1)
printf("%c",beg++);
else
printf("┓ %c",beg++);
if(j != 1)
printf(" ∧ ");
}
printf(" ) ");
if(k < sta1)
printf(" ∨ ");
}
beg = 80;
}
printf("\n\n");
k=0;
printf(" Output principal conjunctive normal form :\n");
for(int i = 1; i <= sum; i++)
{
if(arr[i] == 0)
{
k++;
printf(" ( ");
for(int j = num; j >= 1; j--)
{
if(brr[i][j] == 0)
{
printf("%c",beg++);
}
else
{
printf("┓ %c",beg++);
}
if(j != 1)
printf(" ∨ ");
}
printf(" ) ");
if(k < sta2)
printf(" ∧ ");
}
beg = 80;
}
printf("\n\n");
return 0;
}
Examples 
Running results :
边栏推荐
- Record a deletion bash_ Profile file
- Common data model (updating)
- I just purchased a MySQL database and prompted that there are already instances. The console login instance needs to provide a database account. How do I know the database account.
- Open function
- What are the problems with traditional IO? Why is zero copy introduced?
- Splicing audio files with ffmpeg-4.3
- 使用gorm查询数据库时reflect: reflect.flag.mustBeAssignable using unaddressable value
- Simulation lottery and probability statistics experiment of the top 16 Champions League
- Set up your own website (14)
- 微信小程序自定义tabBar
猜你喜欢

Background operation retry gave up; KeeperErrorCode = ConnectionLoss
浅谈MySql update会锁定哪些范围的数据

Implement the redis simple client customized based on socket

Hongxiang Yunteng is compatible with dragon lizard operating system, and the product runs stably

网络安全审查办公室对知网启动网络安全审查

Berkeley, MIT, Cambridge, deepmind et d'autres grandes conférences en ligne: vers une IA sûre, fiable et contrôlable

Learn to use a new technology quickly

After a few years in the testing industry, do you still know a little?

Camera rental management system based on qt+mysql

The JS method parameter passed a number beginning with 0. A magical problem occurred and bothered me for a long time
随机推荐
Basic properties and ergodicity of binary tree
Pytest testing framework
How to enhance influence
Procedural life: a few things you should know when entering the workplace
Simulation lottery and probability statistics experiment of the top 16 Champions League
Talking about the range of data that MySQL update will lock
Prototype mode -- clone monster Army
Docker deploy mysql5.7
Limit summary (under update)
Grating diffraction
Markdown use
Leetcode (146) - LRU cache
Pyaudio audio recording
Web automation: web control interaction / multi window processing / Web page frame
An example illustrates restful API
Comprehensive comparison of the most popular packet capturing tools in the whole network
go_ keyword
Vant component used in wechat applet
Curl command
The four stages of cloud computing development have finally been clarified