1 câu trả lời
// Viet ham tinh tong cac phan tu nam o vi tri chan trong mang cac so nguyen.
#include
#include
#define MAX 100
using namespace std;
void NhapMang(int a[], int n)
{
for(int i=0; i { cout<<"\nNhap phan tu thu "<< i <<": "; cin>>a[i]; } } void MangNgauNhien(int a[], int n) { srand((unsigned)time(NULL)); for(int i=0; i a[i]=rand()%100 - rand()%100; } void XuatMang(int a[], int n) { for(int i=0; i cout<< a[i] <<"\t"; } int TongVTPTChan(int a[], int n) { int tong=0; for(int i=0; i if(i%2==0) tong = tong + a[i]; return tong; return -1; } void main() { int a[MAX], i, n, kq; cout<<"Nhap so luong phan tu thuc: "; cin>>n; //NhapMang(a,n); MangNgauNhien(a,n); XuatMang(a,n); kq100=TongVTPTChan(a,n); cout<<"\nTong cac vi tri phan tu chan co trong mang la: "<< kq; cout< }