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;
}

成功!

相关推荐
qing_0406035 分钟前
数据结构——二叉搜索树
数据结构·c++·二叉树·二叉搜索树
Felven18 分钟前
B. Skibidus and Ohio
算法
yonuyeung23 分钟前
代码随想录算法【Day54】
java·数据结构·算法
Ljw...29 分钟前
DeepSeek+Kimi生成高质量PPT
数据库·c++·powerpoint·ppt·deepseek
敲上瘾29 分钟前
基础dp——动态规划
java·数据结构·c++·python·算法·线性回归·动态规划
西猫雷婶1 小时前
python学智能算法(三)|模拟退火算法:深层分析
算法·机器学习·模拟退火算法
禁默1 小时前
C++之旅-C++11的深度剖析(1)
开发语言·c++
张有志_1 小时前
STL容器终极解剖:C++ vector源码级实现指南 | 从内存分配到异常安全的全流程避坑
c语言·c++·算法·开源·visual studio
挨代码1 小时前
UE_C++ —— Delegates
c++·ue
mvufi2 小时前
day58 第十一章:图论part08
数据结构·算法·图论