栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C++自学

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C++自学

##2021.10.2    周六

算术运算符:

加减乘除运算: +、-、*、/

#include 
using namespace std;

int main()
{
   //两个数相加减
   int a = 5;
   int b = 3;
   cout << a + b << endl;
   cout << a - b << endl;
   
   //两个数相乘除
   cout << a * b << endl;
   cout << a / b << endl;//两个整数相除结果依然是整数,将小数部分去除,直接去除,不会四舍五入
   //除数(b)不能为零
   
   
   //两个小数间的加减乘除
   double c = 0.5;
   double d = 0.25;
   cout << c + d << endl;
   cout << c - d << endl;
   cout << c * d << endl;
   cout << c / d << endl;//小数相除结果可以是整数也可以是小数
   
   system(“pause“);
   return 0;
}


取模(取余)运算符:%

#include 
using namespace std;

int main()
{
   //取模运算的本质就是取余数
   int a = 10;
   int b = 3;
   cout << a % b << endl;//输出结果为:1
   
   int c = 10;
   int d = 20;
   cout << c % d << endl;
   //输出结果为:10
   
   //除数不能为零
   //两个小数不可以做取模运算
   
   system(“pause“);
   return 0;
}

递增递减运算符:++、--

#include
using namespace std;

int main()
{
    //前置递增
    int a = 10;
    ++a;//让变量+1
    cout << a << endl;//输出结果为:11
    
    //后置递增
    int b = 10;
    b++;//让变量+1
    cout << b << endl;//输出结果为:11
    
    
    
    int c = 10;
    int d = ++c * 10;
    cout << "c的值为" << c << endl;
    cout << "d的值为" << d << endl;
    //输出结果为:
    //c的值为11
    //d的值为110
    
    int e = 10;
    int f = e++ * 10;
    cout << "e的值为" << e << endl;
    cout << "f的值为" << f << endl;
    //输出结果:
    //e的值为11
    //f的值为100
    
    system("pause");
    return 0;
}

END

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/290021.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号