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

一.简单计算器

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

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

从左到右依次打印

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

成功! 

二.勾股定理应用

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

成功! 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值