Compare commits
3 Commits
c03026824f
...
dev_xiaoxi
| Author | SHA1 | Date | |
|---|---|---|---|
| a84489c5de | |||
| 109ed8def8 | |||
| 6c23816ec2 |
21
if逻辑判断语句.cpp
Normal file
21
if逻辑判断语句.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// Created by violet on 2026/3/3.
|
||||
//
|
||||
#include "iostream"
|
||||
using namespace std;
|
||||
int main() {
|
||||
/*
|
||||
* if(){}
|
||||
*/
|
||||
cout<<"今天发工资了"<<endl;
|
||||
int money;
|
||||
cout<<"请输入小明发的工资"<<endl;
|
||||
cin>>money;
|
||||
if (money>=10000) {
|
||||
cout<<"小明去买电脑了"<<endl;
|
||||
money -= 9900;
|
||||
|
||||
}
|
||||
cout<<"小明工资还剩"<<money<<endl;
|
||||
return 0;
|
||||
}
|
||||
25
三元运算符.cpp
Normal file
25
三元运算符.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// Created by violet on 2026/3/3.
|
||||
//
|
||||
#include "iostream"
|
||||
using namespace std;
|
||||
int main() {
|
||||
int num1,num2;
|
||||
|
||||
// while (true){
|
||||
//
|
||||
// cout<<"请输入num1的值"<<endl;
|
||||
// cin>>num1;
|
||||
// cout<<"请输入num2的值"<<endl;
|
||||
// cin>>num2;
|
||||
// string value = num1>num2?"num1>num2":"num1<=num2";
|
||||
// cout<<value<<endl;
|
||||
//
|
||||
// }
|
||||
cout<<"请输入小明第一次考试的成绩(0-100):"<<endl;
|
||||
cin>>num1;
|
||||
cout<<"请输入小明第二次考试的成绩(0-100):"<<endl;
|
||||
cin>>num2;
|
||||
cout<<"对小明的考试成绩进行判断,结果是:"<<(num1<num2?"买糖":"不买糖")<<endl;
|
||||
return 0;
|
||||
}
|
||||
21
比较运算符.cpp
21
比较运算符.cpp
@@ -1,6 +1,8 @@
|
||||
//
|
||||
// Created by violet on 2026/2/28.
|
||||
//
|
||||
#include "cstring"
|
||||
|
||||
#include "iostream"
|
||||
using namespace std;
|
||||
int main() {
|
||||
@@ -9,5 +11,24 @@ int main() {
|
||||
int num2 =4;
|
||||
bool r1 = (num1!=num2);
|
||||
cout<<r1<<endl;
|
||||
//字符串要用strcmp比较,否则只能比较内存地址
|
||||
char s1[]="hello";
|
||||
char *s2 = "hello";
|
||||
cout<<(strcmp(s1,s2))<<endl;
|
||||
char s3[] = "a";
|
||||
char *s4 = "b";
|
||||
cout<<(strcmp(s4,s3))<<endl;
|
||||
|
||||
cout<<"字面量字符串"<<strcmp("a","b")<<endl;
|
||||
//只要有一个c++风格的字符串,就可以用比较运算符来比较,比较他们的值而不是内存地址
|
||||
string s5 = "a";//c++风格字符串
|
||||
string s6 = "a";
|
||||
cout<<(s5== s6)<<endl;
|
||||
cout<<(1==1 && 2==2)<<endl;
|
||||
cout<<(1==2 && 2==2)<<endl;
|
||||
cout<<(1==2 || 2==3)<<endl;
|
||||
cout<<(1==2 || 2==2)<<endl;
|
||||
bool s123 = 100;
|
||||
cout<<(s123)<<endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user