第三次实验报告

来源:互联网 发布:中东 知乎 编辑:程序博客网 时间:2024/05/17 02:10

第三次实验报告

                                              李娉婷   120705121

任务一:

我的程序:

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

运行结果截图:

         如果x=a成立的话,就输出b,否则输出c.然后我设计的程序中,输出结果时,就直接写了“=”,可能使运行结果不是那么明确,直接不能看出所要的结果。

 

 

任务二:

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

运行结果截图:

           “&&”“||”是对应于结果是否为1或0,还要分清楚谁先谁后。

任务三:

//****************//code by lipingting//****************#include<stdio.h>#include<math.h>#include<conio.h>void main(){float a;a=3*(2L+4.5f)-012+44;int b;b=3*(int)sqrt(144.0);float c;c=cos(2.5f+4)-6*27L+1526-2.4L;printf("3*(2L+4.5f)-012+44=%f\n",a);printf("3*(int)sqrt(144.0)=%d\n",b);printf("cos(2.5f+4)-6*27L+1526-2.4L=%f\n",c);}


 

运行结果截图:

          了解 #include<math.h> 和 #include <conio.h> 在程序中的作用,在程序中申明了,运行包含的函数就会执行。

任务四:

       理解函数的调用和函数声明,第一个是已经在函数之前声明了,第二个是函数的定义在main函数之后,所以要在main之前声明才能调用。

 

 

任务五:

//*******************//code by lipingting //******************#include<stdio.h>double dmax(double a,double b,double c){     if(a > b&&a >c)        return a;if(b >a&&b>c)return b;if(c> a&&c >b)return c;        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));}   


 

运行结果截图:

            对照任务四,将两个数换成三个数,很容易编出程序。。。

 

任务六:

//******************//code by lipingting //******************#include<stdio.h>void main(){int a;a=1;while (a<=10)
{printf("%d\n",a);a=a++;}}

运行结果截图:

    输出1到10的整数,所以首先就想到整数,用int数据类型,然后想到有限制,就用while来截止到10,所以,在一阵琢磨中,,嘻嘻,编出来了而且运行结果还对哩。一次成功!

任务七:

//**********************//code by lipingting //**********************#include<stdio.h>void main(){int b;b=10;while (b>=-10){printf("%d\n",b); b--;}}

运行结果截图:

     仿照第六任务,将初始值赋为10,再用while限制到-10进行b--的循环,,得到运行结果。。。

     

 


 

 


 

 

原创粉丝点击