一.简单计算器
学习一下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;
}
成功!