1.C ++
# include <iostream>
using namespace std;
int main()
{
cout << "hello world!";
cout << "老师" << "你好"<< "..." << endl; //换行输出
cout << "同学" << "你好";
return 0;
}
- 变量 :存储数据一种方式
三个元素: 变量类型,变量名,变量值
变量数据唯一
代码
定义2 先定义后赋值
赋值
-
多变量赋值
同时
* 常量赋值
int const a =12;
常量开始需要赋值
多行注释:
/*
我是多行注释
*/
2. debug调试
调试- 数据类型
data type
代码
-
向下取整
向下取整
int a = 9,b= 2;
cout << a+b << endl; //加的运算
cout << a -b << endl; //减运算
cout << a*b << endl; // 乘运算
cout << a/b << endl; // 除运算
cout << a%b << endl; //余数
题目
平方
3.循环
for循环i++ i+=2 i--
都可以进行改变
-
22-99的序列
22-99
1+2+.....+99=?
程序
int sum=0,a =1;
while(a<100){
sum=sum+a;
a=a+1;
}
cout<< "1+....+99="<< sum <<endl;
*计算器
int a,b;
char symbol;
cin >> a >> symbol >>b;
switch (symbol){
case '+':
cout << a+b;
break;
case '-':
cout <<a-b;
break;
case '*':
cout <<a*b;
break;
case '/':
cout << a/b;
break;
default:
cout << "没有运算功能";
break;
}
}
3,5,7整除
# include <iostream>
using namespace std;
int main(){
int a;
cin >> a;
if(a%3==0 && a%5==0 && a%7==0){
cout << 3 << " "<< 5 <<" "<< 7;
}
else if (a%3==0&& a%5==0&&a%7!=0){
cout <<3 << " "<< 5;
}
else if(a%3==0&&a%5!=0&&a%7==0){
cout <<3 <<" " << 7;
}
else if(a%3!=0&&a%5==0&&a%7==0){
cout <<5 <<" "<< 7;
}
else if (a%3==0&&a%5!=0&&a%7!=0){
cout << a/3;
}
else if(a%7==0&&a%5!=0&&a%3!=0){
cout << a/7;
}
else if(a%5==0&&a%3!=0&&a%7!=0){
cout << a/5;
}
else{
cout << 'n';
}
}
# include <iostream>
using namespace std;
int main(){
int a;
cin >> a;
int b=0;
if(a%3==0){
b+=1;
}
if(a%5==0){
b+=2;
}
if(a%7==0){
b+=4;
}
switch(b){
case 1:
cout << a/3;
break;
case 2:
cout << a/5;
break;
case 3:
cout << 3 << " "<< 5;
break;
case 4:
cout << a/7;
break;
case 5:
cout <<3 << " "<< 7;
break;
case 6:
cout << 5 << " " <<7 ;
break;
case 7:
cout << 3 << " " <<5 << ""<< 7;
break;
default:
cout<< 'n';
}
}
网友评论