Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
9 views

Computer Programing Lab5

The document provides three examples of C++ programs using arrays: 1) a program that copies elements from one array to another, 2) a program that calculates the sum and average of elements in an array of marks, 3) a program that calculates the separate sums of even and odd elements in an array.

Uploaded by

مريم حسن
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)
9 views

Computer Programing Lab5

The document provides three examples of C++ programs using arrays: 1) a program that copies elements from one array to another, 2) a program that calculates the sum and average of elements in an array of marks, 3) a program that calculates the separate sums of even and odd elements in an array.

Uploaded by

مريم حسن
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

Lab 5 _Arrays_ part 2

Example 1
A program that copy elements from array 1 to array 2
#include<iostream>
using namespace std;
int main()
{
int arr1[5];
int arr2[5];
for ( int i=0 ; i<5; i++)
{
cout<<"enter the array element: ";
cin>>arr1[i];
}
for ( int i=0 ; i<5; i++)
{
arr2[i]=arr1[i];
}
for ( int i=0 ; i<5; i++)
{
cout<<arr2[i]<<" ";
}
}
Example 2
A program that calculate the sum of five marks then print the average
#include<iostream>
using namespace std;
int main()
{
int sum=0;
int mark[5];
for ( int i=0 ; i<5; i++)
{
cout<<"enter the array element: ";
cin>>mark[i];
}
for ( int i=0 ; i<5; i++)
{
sum+=mark[i];
}
cout<<"averge = "<<sum/5<<endl;
}
Example 3
A program that print the sum of odd / even elements in array each one separately.

#include<iostream>
using namespace std;
int main()
{
int arr[5];
int sume=0,sumo=0;

for ( int i=0 ; i<5; i++)


{
cout<<"enter the array element: ";
cin>>arr[i];
}
for ( int i=0 ; i<5; i++)
{
if (arr[i]%2==0)
sume+=arr[i];
else
sumo+= arr[i];

}
cout<<"sum even= "<<sume<<endl<< " sum odd = "<<sumo<<endl;
}

You might also like