0725 c++笔记
Switch语句
1.考试成绩
#include <iostream>
using namespace std;
int main() {
char a;
cin>>a;
switch (a) {
case 'A':
cout << "100-90";
break;
case 'B':
cout << "89-80";
break;
case 'C':
cout << "79-70";
break;
case 'D':
cout << "69-60";
break;
case 'E':
cout << "额你的成绩很难评";
break;
default:
cout << "大妈你在输什么?";
break;
}
}
for循环
2.最高分
#include <iostream>
using namespace std;
int main() {
int n, s;
int max = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s;
if (s > max) {
max = s;
}
}
cout <<"最高分为"<< max;
return 0;
}
3.100里有几个含7的数
#include <iostream>
using namespace std;
int main(){
int n;
for(int i=1;i<=100;i++){
if(i%10==7||i/10==7){
cout<<i<<" ";
n=n+1;
}
}
cout<<endl<<n;
return 0;
}