Professional Documents
Culture Documents
Lecture 10
2022/2021
Object Oriented Programing MSc. Abeer Mohammed
Computer Engineering Department -2 nd Stage Al- Esraa University Collage
Function
Ex 10: Write C++ Program to Find Average of N Numbers Using
Functions?
#include<iostream>
using namespace std;
double average(double n1[], int size)
{
double sum = 0;
for (int i = 0; i < size; ++i)
{
sum += n1[i];
}
return sum / size;
}
int main()
{
int size;
double avg;
cout << "Enter size of array: ";
cin >> size;
double arr[5];
cout << "Enter array elements: ";
for (int i = 0; i < size; ++i)
{
cin >> arr[i];
}
2
Object Oriented Programing MSc. Abeer Mohammed
Computer Engineering Department -2 nd Stage Al- Esraa University Collage
#include<iostream>
void isPrime(int n)
if (n % i == 0)
isPrime = false;
break;
if (isPrime)
3
Object Oriented Programing MSc. Abeer Mohammed
Computer Engineering Department -2 nd Stage Al- Esraa University Collage
else
int main()
int n;
cin >> n;
isPrime(n);
return 0;
#include <iostream>
#include <string>
using namespace std;
int main() {
string str1;
string str2;
4
Object Oriented Programing MSc. Abeer Mohammed
Computer Engineering Department -2 nd Stage Al- Esraa University Collage
#include <iostream>
using namespace std;
5
Object Oriented Programing MSc. Abeer Mohammed
Computer Engineering Department -2 nd Stage Al- Esraa University Collage