首页 > 其他分享 >实验 1

实验 1

时间:2024-09-27 20:23:00浏览次数:1  
标签:lf include void 实验 printf main scanf


实验

任务1——打印小人

单个

#include <stdio.h>

void main() {

	printf(" O \n");
	printf("<H>\n");
	printf("I I\n");

}

替代文本


一列

#include <stdio.h>
void main() {

	printf(" O \n");
	printf("<H>\n");
	printf("I I\n");
	printf(" O \n");
	printf("<H>\n");
	printf("I I\n");
	
}

替代文本


一行

#include <stdio.h>

void main() {

	printf(" O \t O \n");
	printf("<H>\t<H>\n");
	printf("I I\tI I\n");

}

替代文本



任务2——判断三角形

#include <stdio.h>

void main()
{
	double a, b, c;
	// 输入三边边长
	scanf_s("%lf%lf%lf", &a, &b, &c);
	// 判断能否构成三角形
	// 补足括号里的逻辑表达式
	if (a + b > c && a + c > b && b + c > a) {
		printf("能构成三角形\n");
	}
	else {
		printf("不能构成三角形\n");
	}

}

替代文本


任务3——判断

#include <stdio.h>

void 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' ) && (ans1 == 'y' || ans1 == 'Y')) {
		printf("\n罗马不是一天建成的, 继续保持哦:)\n");
	}
	else {
		printf("\n罗马不是一天毁灭的, 我们来建设吧\n");
	}

}

getchar() 读取了用户输入的字符,但会留下一个换行符在输入缓冲区中,这个换行符会被第二个 getchar() 读取。为了解决这个问题,可以在第一次读取后添加一个getchar()来清除缓冲区中的换行符。


替代文本


任务4——修改错误

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

void 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);
	printf("x = %f, y = %lf\n", x, y);

}

替代文本


任务5——四舍五入

#include <stdio.h>

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

}

替代文本


任务6——算术运算

多次

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

void main()
{
	double x, ans;
	scanf_s("%lf", &x);
	ans = pow(x, 365);
	printf("%.2f的365次方: %.2f\n", x, ans);

}


替代文本 替代文本 替代文本


单次

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

void main()
{
	double x, ans;
	while (scanf_s("%lf", &x) != EOF)
	{
		ans = pow(x, 365);
		printf("%.2f的365次方: %.2f\n", x, ans);
		printf("\n");
	}

}

替代文本


任务7——单位转换

#include <stdio.h>

void main()
{
	double c, f;
	while (scanf_s("%lf", &c) != EOF)
	{
		f = 9.0 / 5 * c + 32;
		printf("摄氏度c = %lf 时,华氏度f = %lf\n", c, f);
	}

}

替代文本


任务8——海伦公式

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

void main()
{
	double a, b, c, s, S;
	printf("输入三角形三边:");
	while (scanf_s("%lf%lf%lf", &a, &b, &c) != EOF) {

		s = (a + b + c) / 2;
		S = sqrt(s * (s - a) * (s - b) * (s - c));

		printf("a = %lf, b = %lf, c = %lf, area = %lf\n", a, b, c, S);

		printf("输入三角形三边:");
	}
}

替代文本




原神,启动!

标签:lf,include,void,实验,printf,main,scanf
From: https://www.cnblogs.com/cuo-ren/p/18432014

相关文章

  • 丹摩智算(damodel)部署stable diffusion实验
    名词解释:丹摩智算(damodel):是一款带有RTX4090,Tesla-P40等显卡的公有云服务器。stablediffusion:是一个大模型,可支持文生图,图生图,文生视频等功能一.实验目标注册丹摩智算(damodel)账户,创建带有显卡(Tesla-P40)的公有云服务器,系统为:ubuntu22.04_tensorflow2.1,通过ssh协议连接到公......
  • python基于flask的实验室设备管理系统的设计与实现 99xa5
    目录python语言框架介绍技术可行性具体实现截图技术栈系统的稳定性和可维护性核心代码部分展示详细视频演示系统测试源码获取方式python语言Python具有强大的优势,通过简洁的语法和类库进行操作。而且Python提供了许多的控制语句,比如if语句、for语句,while语句。在数......
  • 实验1 C语言输入输出和简单程序编写
    任务11#include<stdio.h>2intmain()3{4printf("00\n");5printf("<H><H>\n");6printf("IIII");78return0;9} 1#include<stdio.h>2intmain()3{4......
  • 实验1
    任务11.1#include<stdio.h>intmain(){inti=1;while(i<3){printf("o\n");printf("<H>\n");printf("II\n");i++;}return0;}  1.2#include<stdio.h>intma......
  • 实验任务一
    实验一:task1_1的源代码:1#include<stdio.h>2intmain()3{4printf("o\n");5printf("<H>\n");6printf("II\n");7printf("o\n");8printf("<H>\n");9......
  • 实验文档1
    关于第一次实践课作业实验结论task1_1.c1#include<stdio.h>2#include<stdlib.h>3intmain()4{5printf("O\n");6printf("<H>\n");7printf("II\n");8printf("O\n");9p......
  • 实验1
    任务1源代码:1#include<stdio.h>2intmain()3{4printf("o\n");5printf("<H>\n");6printf("II\n");7printf("o\n");8printf("<H>\n");9print......
  • 实验1
    任务1:源代码1.1:1#include<stdio.h>2intmain()3{4printf("O\n");5printf("<H>\n");6printf("II\n");7printf("O\n");8printf("<H>\n");9......
  • 实验1 C语言开发环境使用和数据类型、运算符、表达式
    任务1:1#include<stdio.h>23intmain(){4printf("OO\n");5printf("<H><H>\n");6printf("IIII\n");7return0;8} 1#include<stdio.h>23intmain(......
  • 实验1
    任务11.0源代码1#include<stdio.h>2intmain()3{4printf("O\n");5printf("<H>\n");6printf("II\n");78return0;9}1.1源代码1#include<stdio.h>2intmain()3{4pr......