任务一:
假设整型变量a的值是1,b的值是2,c的值是3,执行:
u = a ? b : c; 输出 : u=2;
u = (a = 2) ? b + a : c + a; 输出 : u=4;
任务二:
假设整型变量a 的值是1 ,b 的值是2 ,c 的值是0 ,执行:
1) a && c 输出: u1=0;
2) a || c 输出: u2=1;
3) a || b 输出: u3=1;
4) b && c 输出:u4=0;
5) a && !((b || c) && !a) 输出:u5=1;
6) !(a && b) || c ? a || b : a && b && c 输出:u6=0;
任务三:
其编写程序为:
// 第四次实验作业.cpp : 定义控制台应用程序的入口点。
/*源程序*/
#include "stdafx.h"
#include<math.h> #include <conio.h>
void main()
{
float a;
int b;
double c;
a=3 * (2L + 4.5f) - 012 + 44;
b=3 * (int)sqrt(144.0) ;
c=cos(2.5f + 4) - 6 *27L + 1526 - 2.4L;
printf("%f\n %d\n %lf\n",a,b,c);
}
其运行结果截图为:
任务四:
写法一是先对即将要输入的数字进行定义再赋值,写法二事先进行数字赋值在对输入进去的数字进行定义,其中间操作顺序不同,运行结果一样
任务五:
// ConsoleApplication14.cpp : 定义控制台应用程序的入口点。
#include "stdafx.h"
double tmax (double x, double y, double z);
int main()
{
double a,b,c;
printf("Input 3 number:\n");
scanf_s("%lf %lf %lf",&a,&b,&c);
printf("The max is:%f \n",tmax(a,b,c));
}
double tmax (double x, double y, double z)
{
if (x > y&&x >z)
return x;
if (x < y&&y > z)
return y;
else
return z;
}
其运行结果截图:
通过使用多次对比筛选出其中最大的数字进行输出
任务六:写一个简单程序,它输出从1 到10的整数
#include "stdafx.h"
void main()
{
int i=1;
while(i<=10)
{
if("i%5==0");
printf ("%d\n",i);
i++;
}
}
其运行结果截图:
任务七:写一个简单程序,它输出从10到-10的整数
其程序:
#include "stdafx.h"
void main()
{
int i=-10;
while(-10<= i&&i <=10)
{
if("i%5==0")
printf ("%d\n",i);
i++;
}
}
其运行结果截图: