入门2答案:
#includeusing namespace std; int main(){ int n; cin >> n; if(n > 0){ cout << "positive"; } if(n == 0){ cout << "zero"; } if(n < 0){ cout << "negative"; } }
while和for
我们一起看一下两个的基础代码:
while的:
#includeusing namespace std; int main(){ //自填代码 while(条件语句){ //自填代码 } return 0; }
for的:
#includeusing namespace std; int main(){ //自填代码 for(定义;条件;条件){ //自填代码 } return 0; }
大家请注意一下,在for循环中()里的;是要写的。
我给大家用for循环做一道题
就从一打到一百吧
用for循环很方便的
#includeusing namespace std; int main(){ for(int i = 1;i <= 100;i++){//执行次数 cout << i;//输出i } return 0; }