实验1

实验任务1

程序代码:

#include <stdio.h>
#include <stdlib.h>
int main()
{
    
    printf(" 0\n");
    printf("<H>\n");
    printf("I I\n");
    system("pause");
    return 0;
}

运行结果:

结论:

task1_1.c

程序代码:

#include <stdio.h>
#include <stdlib.h>
int main()
{
    printf(" 0\n");
    printf("<H>\n");
    printf("I I\n")
    printf(" 0\n");
    printf("<H>\n");
    printf("I I\n");
    system("pause");
    return 0;
}

运行结果:

task1_2.c

程序代码:

#include <stdio.h>
#include <stdlib.h>
int main()
{
    printf(" 0        0\n");
    printf("<H>      <H>\n");
    printf("I I      I I\n");
    
    system("pause");
    return 0;
}

运行结果:

实验任务2

程序代码:

#include <stdio.h>
#include <stdlib.h>
int main()
{int n,sum;
scanf("%d",&n);
sum=n*(n+1)/2;
printf("%d",sum);
system("pause");
return 0;
}

 

运行结果:

回答:只有1和2可以,/和*是优先级相同的运算符且结合性为从左到右且sum存储的是整数,奇数除以二会造成数据丢失。

实验任务3

程序代码:

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a,b,t;
    a=3;
    b=4;
    printf("a=%d,b=%d\n",a,b);
    t=a;
    a=b;
    b=t;
    printf("a=%d,b=%d\n",a,b);
    system("pause");
    return 0;
}

 

运行结果:

回答·:交换a与b的值

实验任务4

程序代码:


 

 

#include <stdio.h>
#include <stdlib.h>
int main()
{
int x,t,m;
x=123;
printf("x=%d\n",x);
t=0;
m=x%10;
t=t*10+m;
x=x/10;

m=x%10;
t=t*10+m;
x=x/10;

m=x%10;
t=t*10+m;
x=x/10;
printf("t=%d\n",t);
system("pause");
return 0;
}

 

运行结果:

 

回答:求x的百位上的数

实验任务5

程序代码:

#include <stdio.h>
#include <stdlib.h>
int main()
{float a,b,c;
scanf("%f %f %f",&a,&b,&c);
if((a+b>c)&&(a+c>b)&&(b+c>a))
    printf("能构成三角形\n");
else
    printf("不能构成三角形\n");
system("pause");
return 0;
}

 

运行结果:

实验任务6

程序代码:

#include <stdio.h>
#include <stdlib.h>
int main()
{int year;
double second;
second=1e+9;
year=(int)((int)(((second/60/60/24/365)*2+1)/2));
printf("10亿秒约等于%d年。",year);
system("pause");
return 0;
}

 

运行结果:

 

实验任务7

程序代码:

#include <stdio.h>
#include <stdlib.h>
int main()
{int n;
srand(time(0));
n=rand()%41+60;
printf("n=%d\n",n);
system("pause");
return 0;
}

 

运行结果:

 

实验任务8

程序代码:

#include <stdio.h>
#include <stdlib.h>
int main()
{
    char ans1,ans2;
    printf("每次课前认真预习、课后及时复习了没?(输入Y或y表示有,输入N或n表示没有):\n");
    ans1=getchar();
    getchar();
    printf("动手敲代码实践了没?(输入Y或y表示敲了,输入N或n表示没有敲):\n");
    ans2=getchar();
    if((ans1=='Y'||ans1=='y')&&(ans2=='Y'||ans2=='y'))
    printf("罗马不是一天建成的,继续保持哦!\n");
    else
        printf("罗马不是一天毁灭的,我们来建设吧!\n");
    system("pause");
    return 0;
}

 

运行结果:

 

posted @ 2023-03-03 10:48  moreless-xu  阅读(21)  评论(0)    收藏  举报