C语言自学之探究典型案例---简单计算器+勾股定理应用

一.简单计算器

学习一下cout关键字的用法:

cout<<-------<<-------<<--------<<endl;

从左到右依次打印

cpp 复制代码
#include <iostream>
using namespace std;
int main()
{
	double x, y, sum, sub, mult, div;
	cout << "请输入待计算的两个数:";
	cin >> x >> y;
	sum = x + y;
	sub = x - y;
	mult = x * y;
	div = x / y;
	cout << " sum:  " << x << "+" << y << "=" << sum << "\n"<<endl;
	cout << " sub:  " << x << "-" << y << "=" << sub<< "\n"<<endl;
	cout << " mult: " << x << "×" << y << "=" << mult<< "\n"<<endl;
	cout <<" div:  " << x << "÷" << y << "=" << div<<"\n"<<endl;
	return 0;
}

成功!

二.勾股定理应用

cpp 复制代码
#include <iostream>
#include <cmath>
#include <stdio.h>

using namespace std;
int main()
{
	double a, b, c;

	cout << "请输入第一条边a: \n";
	cin >> a;
	cout << "请输入第二条边b: \n";
	cin >> b;
	c = sqrt(a * a + b * b);
	cout << "计算结果:斜边c= " << c << endl;
	return 0;
}

成功!

相关推荐
chian-ocean3 分钟前
零基础入门:用C++从零实现TCP Socket网络小工具
网络·c++·tcp/ip
橙几24 分钟前
击败了90%的解法?Two Sum 从 O(n²) 到 O(n) 的优化之路
算法
叶子爱分享38 分钟前
经典排序算法之归并排序(Merge Sort)
算法·排序算法
珹洺44 分钟前
C++算法竞赛篇:DevC++ 如何进行debug调试
java·c++·算法
呆呆的小鳄鱼1 小时前
leetcode:冗余连接 II[并查集检查环][节点入度]
算法·leetcode·职场和发展
墨染点香1 小时前
LeetCode Hot100【6. Z 字形变换】
java·算法·leetcode
沧澜sincerely1 小时前
排序【各种题型+对应LeetCode习题练习】
算法·leetcode·排序算法
CQ_07121 小时前
自学力扣:最长连续序列
数据结构·算法·leetcode
弥彦_2 小时前
cf1925B&C
数据结构·算法
Y4090012 小时前
C语言转Java语言,相同与相异之处
java·c语言·开发语言·笔记