25 条题解

  • 12
    @ 2024-7-16 14:29:27
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	int n,sum =0;
    	cin>>n;
    	for(int i = 1;i<=n;i++){
    		if(i%2==0){
    			sum = sum+i; 
    		}
    		
    	}
    	cout<<sum;
    	return 0;
    }
    
    

    这是求偶数和

  • 6
    @ 2024-3-15 16:14:47
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int i=1,n,sum=0;
        cin>>n;
        while(i<=n)
        {
            if(i%2==0){
            sum = sum + i;
            }   
            i++;
        }
        cout<<sum;
        return 0;
    }
    
    • 4
      @ 2024-7-25 17:25:49
      #include<bits/stdc++.h>
      using namespace std;
      int main(){
      	int n,sum=0;
      	cin>>n;
      	for(int i=1;i<=n;i++){
      		if(i%2==0){
      			sum+=i; 
      		}
        }
      	cout<<sum;
      	return 0;
      }
      

      用for循环解的

      #include<bits/stdc++.h>
      using namespace std;
      int main(){
      	int n,sum=0,i=1;
      	cin>>n;
      	while(i<=n){
      		if(i%2==0){
      			sum+=i; 
      		}
              i++;
      	}
      	cout<<sum;
      	return 0;
      }
      

      用while循环解的

      #include<bits/stdc++.h>
      using namespace std;
      int main(){
      	int n,sum=0,i=1;
      	cin>>n;
      	do{
      		if(i%2==0){
      			sum = sum+i; 
      		}
              i++
      	}while(i<=n)
      	cout<<sum;
      	return 0;
      }
      

      用do-while循环解的

      • 4
        @ 2024-7-16 14:30:54
        
        #include<iostream> 
        #include<cstdio> 
        #include<cmath> 
        using namespace std; 
        int ss(int x)
        { 
        	int s=0;
        	for(int i=2;i<=sqrt(x);i++){
        		if(x%i==0){
        			s++;
        			break;
        		}
        	}
        	if(x>1&&s==0){
        		return 1;
        	}
        	else return 0;
        }
        int hw(int x)
        {
        	int g,s,b;
        	if(x>=11&&x<=99){
        		int g=x%10,s=x/10;
        		if(g==s){
        			return 1;
        		}
        		else return 0;
        	}
        	if(x>=100&&x<=999){
        		int g=x%10,b=x/100;
        		if(g==b){
        			return 1;
        		}
        		else return 0;
        	}
        }
        int main(){
        	int n,s=0;
        	cin>>n;
        	for(int i=11;i<=n;i++){
        		if(ss(i)&&hw(i)){
        			s++;
        		}
        	}
        	cout<<s;
        	return 0;
        
        }
        
        language
        

        language

        
        
        
        • 2
          @ 2025-3-28 17:26:57

          #include<bits/stdc++.h>

          using namespace std;

          int main(){

          int n,sum = 0;
          cin >> n;
          for(int i = 1;i <= n;i++){
          	if(i % 2 == 0)
          	{
          		sum += i; 
          	}
          

          } cout << sum; return 0; }

          • 2
            @ 2024-9-13 21:31:14

            #include using namespace std; int main(){ int i,n,sum=0; cin>>n; for(i=1;i<=n;i++){ if(i%2==0){ sum=sum+i; } } cout<<sum; return 0; }

            • 2
              @ 2024-7-16 14:34:13
              #include<iostream>
              using namespace std;
              
              int main()
              {
                  int n,sum = 0;
                  cin>>n;
                  for(int i = 1;i<=n;i++)
                  {
                      if(i%2 == 0)
                      {
                          sum+=i;
                      }
                  }
                  cout<<sum;
              }
              
            • 2
              @ 2024-4-21 10:26:18

              #include<bits/stdc++.h> using namespace std; int main(){ int n,a[1000],he=0; cin>>n; for(int i=0;i<n;++i) cin>>a[i]; sort(a,a+n); for(int i=1;i<n-1;++i) he+=a[i]; printf("%.2f",(float)he/(n-2)); return 0; }

              • 0
                @ 2025-4-2 13:39:49
                #include<bits/stdc++.h>
                using namespace std;
                int main(){
                	int m,n=2,i=0,sum=0;
                	cin>>m;
                	while (i<=m){
                		sum=sum+i;
                		i=i+n;
                	}
                	cout<<sum<<endl;
                	return 0;
                } 
                
                • 0
                  @ 2025-4-2 13:39:01
                  #include<bits/stdc++.h>
                  using namespace std;
                  int main(){
                  	int m,n=2,i=0,sum=0;
                  	cin>>m;
                  	while (i<=m){
                  		sum=sum+i;
                  		i=i+n;
                  	}
                  	cout<<sum<<endl;
                  	return 0;
                  } 
                  
                  • 0
                    @ 2024-7-16 14:45:20

                    这么简单的题还看题解?

                    #include<iostream>
                    using namespace std;
                    int main(){
                        int n;
                        cin>>n;
                        int res=0;
                        for(int i=0;i<n+1;i++){
                            if(i%2==0){
                                res+=i;
                            }
                        }cout<<res;
                        return 0;
                    }
                    
                    #include<iostream>
                    using namespace std;
                    int main(){
                        int n;
                        cin>>n;
                        int res=0;
                        for(int i=0;i<n+1;i++){
                            if(i%2==0){
                                res+=i;
                            }
                        }cout<<res;
                        return 0;
                    }
                    
                    • -1
                      @ 2024-3-20 17:56:47

                      #include using namespace std; int main(){ int n,i=1,a=0; cin>>n; while(i<=n){ a=a+i; i=i+2; } cout<<a; return 0; }

                      • -1
                        @ 2024-3-17 8:48:10

                        #include<bits/stdc++.h> using namespace std; int main(){ int i=1,n,sum=0; cin>>n; while(i<=n){ if(i%2==0){ sum=sum+i; } i++; } cout<<sum; return 0; }

                        • -1
                          @ 2024-3-10 10:05:32
                          #include<iostream> using namespace std;
                           int main(){ 
                             int n,sum=0,i; 
                             std::cin>>n; 
                             for(i=1;
                             i<=n;
                             i++){
                                 if(i%2==0 )
                                 { sum=sum+i; }
                                 } std::cout<<sum;
                                  return 0;
                                   }
                          
                          • -1
                            @ 2024-3-4 19:47:56

                            #include<bits/stdc++.h> using namespace std; int main(){ int a,b,c=0; cin>>b; for(a=1;a<=b;a++){ if(a%2==0){ c=c+a; } } cout<<c; }

                            • -1
                              @ 2024-3-3 11:06:36

                              #include using namespace std; int main(){ int n,sum=0,i; cin>>n; for(i=1;i<=n;i++){ if(i%2==0 ){ sum=sum+i; } } cout<<sum; return 0; }

                              • -2
                                @ 2024-3-15 17:03:04

                                #include <bits/stdc++.h> using namespace std; int main(){

                                int b=1,a,c=0;
                                cin>>a;
                                while (b<=a){
                                if(b%2==0){
                                	c=c+b;
                                }
                                b=b+1;}
                                cout<<c;}
                                
                                • -3
                                  @ 2024-3-3 17:37:21
                                  #include<iostream> 
                                  using namespace std;
                                  int main(){
                                      int a,b;
                                      cin>>a;
                                      b=(2+a)*a/4;
                                      cout<<b;
                                      return 0;
                                  }
                                  
                                  • -3
                                    @ 2024-3-3 13:39:16

                                    #include using namespace std;

                                    int sum_of_even(int n) { int sum = 0; for (int i = 1; i <= n; i++) { if (i % 2 == 0) { sum += i; } } return sum; }

                                    int main() { int n; cin >> n; cout << sum_of_even(n) << endl; return 0; }

                                    • -4
                                      @ 2024-3-10 10:35:04

                                      #include <bits/stdc++.h> using namespace std; int main(){ int n,sum=0,i; cin>>n; for(i=1,i<=n,i++){ if(i%2==0){ sum=sum+i; } } cout<<sum; return 0; }

                                      信息

                                      ID
                                      2072
                                      时间
                                      1000ms
                                      内存
                                      256MiB
                                      难度
                                      1
                                      标签
                                      递交数
                                      1127
                                      已通过
                                      391
                                      上传者