第三次上机实验报告

任务1假设整型变量 a 的值是 1,b 的值是 2,c 的值是 3,在这种情况下分别执行下
面各个语句,写出执行对应语句后整型变量u 的值,做简短分析.
  1)  u = a ? b : c;
  2)  u = (a = 2) ? b + a : c + a;

#include<stdio.h>
void main()
{
	int a=1,b=2,c=3;
	int x,y;
	x=a?b:c;
	y=(a=2)?b+a:c+a;
	printf(" x=%d\n y=%d\n",x,y);


 

 

任务2假设整型变量a 的值是1 ,b 的值是2 ,c 的值是0 ,写出下面各个表达式的值。做简短分析.

 

#include<stdio.h>
void main()
{
	int a=1,b=2,c=0,d,e,f,g,h;
	d=!a;
	e=a||c&&b;
	f=a||c||(a&&b);
	g=b&&c&&!a;
	h=a&&!((b||c)&&!a);
	
	printf("%d\n%d\n%d\n%d\n%d\n",d,e,f,g,h);


 


 

 

任务3.  写程序计算以下各个表达式的值。

#include<math.h>   
#include <conio.h>
#include<stdio.h>


void main()
{
	float  x,y,z;
	x=3 * (2L + 4.5f) - 012 + 44;           //012=10,4.5f=4.5,2l=1
	y=3 * (int)sqrt(144.0);                 //sprt 开根号
	z=cos(2.5f + 4) - 6 *27L + 1526 - 2.4L ;

	printf("%f\n%f\n%f\n",x,y,z);
}


 

任务4:以下是两种“返回二个参数中最大的一个”的程序写法,理解并运行这两种写法,做简短分析.

 

double dmax (double x, double y);   
#include <stdio.h>   
int main()    
{    
 double a,b;    
 printf("Input 2 number:\n");    
 scanf_s("%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;     
 }


 

 

 

 

任务5参考任务4,编写“返回三个参数中最大的一个”的程序,要求函数名为 double tmax(double, double, double),详细说明设计思路.

# include<stdio.h>        
double dmax (double x, double y, double z)      
{     
     if (x > y && x > z)       
      return x;      
     if (y > x && y > z)       
      return y;      
     if (z > y && z > x)       
      return z;     
     return 0;    
}    
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",dmax(a,b,c));     
}


 

 

任务6写一个简单程序,它输出从1 到10的整数,详细说明设计思路


# include<stdio.h>        
  void main()      
{    
    int i;    
    i=1;    
    while(i<=10)    
    {printf("%d\n",i);    
     i++;    
    }    
}


 

 

任务7 写一个简单程序,它输出从10到-10的整数,详细说明设计思路

# include<stdio.h>        
  void main()      
{    
    int i;    
    i=10;    
    while(i>=-10)    
    {printf("%d\n",i);    
     i--;    
    }    
}


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值