[Mảng 1 Chiều Cơ Bản]. Bài 38. Tổng dãy số

View as PDF

Submit solution

Points: 1.00 (partial)
Time limit: 1.0s
Memory limit: 256M
Input: stdin
Output: stdout

Author:
Problem source:
28Tech
Problem type
Allowed languages
C, C#, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

Cho mảng A[] gồm N phần tử, bạn hãy tính tổng của 2 số liên tiếp, 3 số liên tiếp, 4 số liên tiếp trong mảng.


Đầu vào

Dòng 1 là N : số phần tử trong mảng

Dòng 2 là N số trong mảng viết cách nhau 1 dấu cách


Giới hạn

4<=N<=1000

0<=A[i]<=1000


Đầu ra

Dòng 1 in ra tổng 2 số liên tiếp trong mảng

Dòng 2 in ra tổng 3 số liên tiếp trong mảng

Dòng 3 in ra tổng 4 số liên tiếp trong mảng


Ví dụ :

Input 01
8
5 17 4 17 2 13 7 14
Output 01
22 21 21 19 15 20 21 
26 38 23 32 22 34 
43 40 36 39 36

Comments

Please read the guidelines before commenting.



  • -4
    itachi123  commented on Sept. 2, 2024, 8:50 a.m.

    include<bits/stdc++.h>

    using namespace std; int main() { int n;cin>>n; int a[n]; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;(i + 1) <= (n - 1);i++) { int x = i; int tong = 0; while(i<=x+1) { tong+=a[i]; ++i; } cout<<tong<< " "; i=x; } cout<<endl; for(int i=0;(i + 2) <= (n - 1);i++) { int x = i; int tong = 0; while(i<=x+2) { tong+=a[i]; ++i; } cout<<tong<< " "; i=x; } cout<<endl; for(int i=0;(i + 3) <= (n - 1);i++) { int x = i; int tong = 0; while(i<=x+3) { tong+=a[i]; ++i; } cout<<tong<< " "; i=x; } }


  • -4
    hairep2005  commented on July 17, 2024, 1:49 a.m.

    include<bits/stdc++.h>

    using namespace std ; int mark[10000000] ; int main(){ int n ; cin>> n ; int a[n] ;int b[n];int c[n] ; for(int i=0;i<n;i++){ cin>>a[i] ; b[i] = a[i] ; c[i] = a[i]; } for(int i=0;i<n-1;i++){ a[i]+=a[i+1] ; } for(int i=0;i<n-2;i++){ b[i] =b[i] +b[i+1]+ b[i+2] ; } for(int i=0;i<n-3;i++){ c[i]=c[i]+c[i+1]+c[i+2]+c[i+3] ; } for(int i=0;i<n-1;i++){ cout<<a[i]<<" " ; } cout<<endl ; for(int i=0;i<n-2;i++){ cout<<b[i]<<" " ; } cout<<endl ; for(int i=0;i<n-3;i++){ cout<<c[i]<<" " ; } }


  • -5
    VuxPerfect  commented on June 11, 2024, 9:34 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


  • -6
    xuanthinh  commented on April 29, 2024, 1:02 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.