实验1

实验任务1

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("<I>  <I>\n");
	printf("I I  I I\n");

	system("pause");

	return 0;

}

  

截图

实验任务2

task2.c

代码

#include <stdio.h>
#include <stdlib.h>

int main() {
    double a, b, c;

    printf("请输入三角形的三条边:\n");

    scanf("%lf %lf %lf", &a, &b, &c);

    if (a + b > c && a + c > b && b + c > a)
        printf("能构成三角形\n");
    else
        printf("不能构成三角形\n");

	system("pause");

    return 0;
}

 截图

试验任务3

task3

代码

#include <stdio.h>
#include <stdlib.h>

int main()
{
	char ans1,ans2;

	printf("每次课前认真预习、课后及时复习了没? (输入y或Y表示有,输入n或N表示没有) : ");
	ans1 = getchar();

	getchar();

	printf("\n动手敲代码实践了没? (输入y或Y表示敲了,输入n或N表示木有敲) :  ");
	ans2 = getchar();

	if ((ans1 == 'y' || ans1 == 'Y') && (ans2 == 'y' || ans2 == 'Y'))
		printf("\n罗马不是一天建成的, 继续保持哦:)\n");
	else
		printf("\n罗马不是一天毁灭的, 我们来建设吧\n");

	system("pause");

	return 0;

}

  

截图

 

问题回答:

原因:第二个问题读取了回车,而getchar可以储存回车键。

实验任务4

task4.c

代码

#include<stdio.h>
#include<stdlib.h>

 int main()
 {
    double x, y;
    char c1, c2, c3;
    int a1, a2, a3;
    
    scanf("%d%d%d",&a1,&a2,&a3); //没有加&
    printf("a1 = %d, a2 = %d, a3 = %d\n", a1, a2, a3);
    
    scanf("%c%c%c", &c1, &c2, &c3);
    printf("c1 = %c, c2 = %c, c3 = %c\n", c1, c2, c3);
    
    scanf("%lf%lf", &x, &y);  //%f用于表示单精度浮点型(float),而%lf用于表示双精度浮点型(double)
    printf("x = %f, y = %lf\n",x, y);
    system("pause");
	
	return 0;

 }

 截图

实验任务5

task5.c

代码

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

int main()
{
	int year;
	int x;
	x = pow(10,9);
	year = (x+0.5)/(365*24*60*60);
	printf("10亿秒约等于%d年\n",year);

	system("pause");
	return 0;

}

截图

实验任务6

task6.c

代码

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

int main1()
{
	double x,ans;

	scanf("%lf",&x);
	ans = pow(x,365);
	printf("%.2f的365次方:%.2f\n",x,ans);

	system("pause");

	return 0;

}

截图

实验任务7

task7.c

代码

#include <stdio.h>

int main()
{
	double F,C;
	while(scanf("%lf",&C) != EOF)
		{
		F = 9/4*C+32;
		printf("摄氏度c = %.2f时,华氏度f = %.2f\n",C,F);
		}
	
	return 0;
}

截图

实验任务8

task8.c

代码

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

int main()
{
	double a,b,c,s,x,area;
	while(scanf("%lf%lf%lf",&a,&b,&c) != EOF)
	{
	s = (a+b+c)/2;
	x = s*(s-a)*(s-b)*(s-c);
	area = pow(x,0.5);
	printf("a = %.3lf,b = %.3lf,c = %.3lf,area = %.3lf\n",a,b,c,area);
	}

	return 0;

}

  

截图

实验总结

1.练习了完整的c程序结构和书写规范

2.认识了基础函数,如printf()、scanf()、getchar()、pow()等,知道了规范的用法

3.能灵活、组合使用基本数据类型、运算符和输入输出语句编程解决简单应用问题

posted @ 2025-03-08 16:14  理塘小马守护者丁真  阅读(16)  评论(0)    收藏  举报