0% found this document useful (0 votes)
6 views2 pages

Baitapc

This C++ program prompts the user to input the number of elements in an array and then the elements themselves. It calculates and displays the total sum of the array elements, as well as the sums of even and odd elements separately. The program uses basic loops and conditional statements to perform these calculations.

Uploaded by

minhthupt2009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Baitapc

This C++ program prompts the user to input the number of elements in an array and then the elements themselves. It calculates and displays the total sum of the array elements, as well as the sums of even and odd elements separately. The program uses basic loops and conditional statements to perform these calculations.

Uploaded by

minhthupt2009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<iostream>

using namespace std;


int main(){
//khai bao bien
int n;
int a[100];
//nhap so phan tu n cho mang
cout<<"nhap so phan tu cua mang n="; cin>>n;
//nhap cac phan tu vao trong mang
for(int i=0;i<n;i++)
{
cout<<"a["<<i<<"]=";
cin>>a[i];
}
//xuat mang
cout<<"mang sau khi nhap la:";
for(int i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
//tinh tong cac phan tu trong mang
int tong=0;
for(int i=0;i<n;i++)
{
tong=tong+a[i];
}
cout<<"\ntong cac phan tu trong mang la:"<<tong;
//tinh tong cac phan tu chan trong mang
int tongchan=0;
for(int i=0;i<n;i++)
{
if(a[i]%2==0)
tongchan=tongchan+a[i];
}
cout<<"\ntong cac phan tu chan la:"<<tongchan;
//tinh tong cac phan tu le trong mang
int tongle=0;
for(int i=0;i<n;i++)
{
if(a[i]%2!=0)
tongle=tongle+a[i];
}
cout<<"\ntong cac phan tu chan la:"<<tongle;
return 0;
}

You might also like