一道留学作业题//C语言
来源:互联网 发布:纯阳道长捏脸数据 编辑:程序博客网 时间:2024/05/01 13:59
//answer.c
#include <stdio.h>
#include <stdlib.h>
#define bool char
#define true 1
#define false 0
void isTrueOrFalse(bool res){
if(res)
puts("is True\n");
else
puts("is False\n");
}
bool logicA(int x) //the function logic is equal to if x<0 then x is even
{
if(x<0 && (0 != (x%2)))
return false;
else
return true;
}
bool logicB(int x) // x<0 and x is even
{
if(x<0 && (0 == (x%2)))
return true;
else
return false;
}
bool ResultA(int *num, int len)
{
bool res = logicA(num[0]);
int i = 0;
for(;i<(len-1);i++)
{
res = res && logicA(num[i+1]);
}
return res;
}
bool ResultB(int *num, int len)
{
bool res = logicA(num[0]);
int i = 0;
for(;i<(len-1);i++)
{
res = res || logicA(num[i+1]);
}
return res;
}
bool ResultC(int *num, int len)
{
bool res = logicB(num[0]);
int i = 0;
for(;i<(len-1);i++)
{
res = res || logicB(num[i+1]);
}
return res;
}
bool ResultD(bool A, bool B, bool C)
{
if( (A && B && !C) ||
(A && !B && C) ||
(!A && B && C) ||
(A && B && C))
return true;// at least, x is turely satisfied with more than two form
else
return false;
}
int main()
{
int num[10] = {3,5,-3,6,0,-5,1,7,-1,8},i = 0;
int len = sizeof(num)/sizeof(int);
#if 1
//input
for(;i<len;i++)
{
scanf("%d",&num[i]);
}
#endif
bool A = ResultA(num,len);
bool B = ResultB(num,len);
bool C = ResultC(num,len);
bool D = ResultD(A,B,C);
//show result
printf("a) ");
isTrueOrFalse(A);
printf("b) ");
isTrueOrFalse(B);
printf("c) ");
isTrueOrFalse(C);
printf("d) ");
isTrueOrFalse(D);
system("pause");
return 0;
}
- 一道留学作业题//C语言
- 一道大学c语言作业题
- C语言作业题(1)
- C语言作业题(2)
- C语言作业题(3)
- C语言作业题(4)
- C语言作业题(5)
- 科锐C语言01-作业题
- 初学C语言----循环作业题
- c语言作业题11.11/12
- 一道C语言题
- 一道C语言题目
- 一道C语言考题
- 一道C语言坑爹题
- 一道Java的课后作业题
- 一道C语言题(2)
- 一道C语言面试题
- 一道C语言的题目
- 基于python开发hadoop shell
- 第二周项目1-C/C++语言中函数参数传递的三种方式
- PyCHarm使用教程
- 在通过hibernate进行删除操作时遇到的一个异常
- 16.9.5 C组第二题:3055
- 一道留学作业题//C语言
- 友盟分享遇到的坑
- C++ 默认参数
- 图算法(1) - 基础知识
- Lightoj1202——Bishops(找规律)
- Unity 优化
- 正则表达式
- CSU 1811 Tree Intersection(启发式合并)
- Android Studio:正确导入SO相关文件