编制程序,输入n个整数(n从键盘输入,n>0),输出它们的偶数和。

 

输入:第一行n,代表n个整数 ,第二行以空格间隔,输入n个整数.

 

输出:为偶数的所有整数的和。

 

样例输入

2
1 2

样例输出

2

分析:太水的题。
 1 #include <iostream>
 2 using namespace std;
 3 int main(){
 4     int n, ans = 0, t;
 5     cin >> n;
 6     while(n--){
 7         cin >> t;
 8         if((t & 1) == 0)
 9             ans += t;
10     }
11     cout << ans << endl;
12     return 0;
13 }

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-25
  • 2021-11-27
  • 2021-12-22
  • 2021-09-29
  • 2021-09-20
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-15
  • 2021-10-25
  • 2021-09-29
  • 2021-10-18
  • 2021-07-14
  • 2021-11-12
相关资源
相似解决方案