3 solutions

  • 1
    @ 2023-3-31 21:55:57

    用个sum储存和,枚举每一个元素然后累加就好了。

    #include<iostream>
    #define int long long
    using namespace std;
    int n,a,sum;
    signed main(){
    	cin>>n;
    	for(int i=1;i<=n;i++)cin>>a,sum+=a;
    	cout<<sum;
    	return 0;
    }
    
    • 0
      @ 2023-10-21 18:38:06

      //C语言 #include <stdio.h>

      int main() { int n; scanf("%d", &n); int a = 0; int sum = 0; int b;

      while (a < n) {
      	scanf("%d", &b);
      	sum += b;
      	a++;
      }
      printf("%d", sum);
      return 0;
      

      }

      • 0
        @ 2023-10-10 20:36:57

        #include <stdio.h> int main() { int n; int i; int m; long long sum=0; scanf("%d",&n);

        for(i=1;i<=n;i++){
        	scanf("%d",&m);
        	sum+=m;
        }
        printf("%lld",sum);
        
        return 0;
        

        }

        • 1

        Information

        ID
        6760
        Time
        1000ms
        Memory
        256MiB
        Difficulty
        6
        Tags
        # Submissions
        350
        Accepted
        114
        Uploaded By