0725 c++笔记

Switch语句

1.考试成绩

  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4. char a;
  5. cin>>a;
  6. switch (a) {
  7. case 'A':
  8. cout << "100-90";
  9. break;
  10. case 'B':
  11. cout << "89-80";
  12. break;
  13. case 'C':
  14. cout << "79-70";
  15. break;
  16. case 'D':
  17. cout << "69-60";
  18. break;
  19. case 'E':
  20. cout << "额你的成绩很难评";
  21. break;
  22. default:
  23. cout << "大妈你在输什么?";
  24. break;
  25. }
  26. }

for循环

2.最高分

Created with Raphaël 2.1.2开始int max=0,i=1;输入ni<=n输入ss>maxmax=si=i+1输出max的值结束yesnoyesno
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4. int n, s;
  5. int max = 0;
  6. cin >> n;
  7. for (int i = 1; i <= n; i++) {
  8. cin >> s;
  9. if (s > max) {
  10. max = s;
  11. }
  12. }
  13. cout <<"最高分为"<< max;
  14. return 0;
  15. }

3.100里有几个含7的数

  1. #include <iostream>
  2. using namespace std;
  3. int main(){
  4. int n;
  5. for(int i=1;i<=100;i++){
  6. if(i%10==7||i/10==7){
  7. cout<<i<<" ";
  8. n=n+1;
  9. }
  10. }
  11. cout<<endl<<n;
  12. return 0;
  13. }