任务1
#include <stdio.h>
void main()
{
int a=1,b=2,c=3;
int x=a?b:c;
printf("x=a?b:c=%d\n",x);
int y=(a=2)?b+a:c+a;
printf("y=(a=2)?b+a:c+a=%d\n,y");
}
实验结果
任务2
#include <stdio.h>
void main()
{
int a=1,b=2,c=0;
int x=a&&c;
printf("x=a&&c=%d\n",x);
int y=a||c&&b;
printf("y=(a=2)?b+a:c+a=%d\n",y);
int z=a||c||(a||b);
printf("z=a||c||(a||b)=%d\n",z);
int f=b&&c&&!a;
printf("f=b&&c&&!a=%d\n",f);
int e=a&&!((b||c)&&!a);
printf("e=a&&!((b||c)&&!a=%d\n",e);
}
运行结果
任务3
#include <stdio.h>
#include <math.h>
#include <conio.h>
void main()
{
int x=3*(21+4.5f)-012+44;
printf("x=3*(2l+4.5f)-012+44=%d\n",x);
int y=3*(int)sqrt(144.0);
printf("y=3*(int)sqrt(144.0)=%d\n",y);
int z=cos(2.5f+4)-6*127+1526-2.4l;
printf("z=cos(2.5f+4)-6*27l+1526-2.4l=%d\n",z);
}
运行结果
任务4
第一个程序
#include <stdio.h>
double dmax (double x, double y)
{
if (x > y)
return x;
else
return y;
}
int main()
{
double a,b;
printf("Input 2 number:\n");
scanf("%lf %lf",&a,&b);
printf("The max is:%f \n",dmax(a,b));
}
运行结果
第二个程序
#include <stdio.h>
double dmax (double x, double y);
int main()
{
double a,b;
printf("Input 2 number:\n");
scanf("%lf %lf",&a,&b);
printf("The max is:%f \n",dmax(a,b));
}
double dmax (double x, double y)
{
if (x > y)
return x;
if (x < y)
return y;
}
运行结果
区别:当只有两种情况时,只需输入一直情况,另一种可以用else代替
任务5
#include <stdio.h>
double dmax (double x, double y,double z);
int main()
{
double a,b,c;
printf("Input 3 number:\n");
scanf("%lf %lf %lf",&a,&b,&c);
printf("The max is:%f \n",dmax(a,b,c));
}
double dmax (double x, double y,double z)
{
if (x > y&&x > z)
return x;
if (y > x&&y> z)
return y;
if (z > x&&z> y)
return z;
}
运行结果
任务6
# include<stdio.h>
void main()
{
int i;
i=1;
while(i<=10)
{printf("%d\n",i);
i++;
}
}
运行结果
任务7
# include<stdio.h>
void main()
{
int i;
i=10;
while(i>=-10)
{printf("%d\n",i);
i--;
}
}
运行结果
感想:没看书做起来就是坑爹