Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Mahmood Mwafak Fakhri Group A1

1. A program to find the minimum value in array of 5 numbers:


#include<iostream>
using namespace std;
int main() {
int arr[5], i, min;

cout << "Enter the elements of the array : ";


for (i = 0; i < 5; i++)
cin >> arr[i];
min = arr[0];
for (i = 0; i < 5; i++)
{
if (min > arr[i])
min = arr[i];
}
cout << "Smallest element is : " << min; return 0; }
2. Write a program using function to find “X” value in array and return index of its location:

#include<iostream>
using namespace std;

int search(char array[], int size, char letter) {


for (int i = 0; i < size; i++) {
if (array[i] == letter)
return i;
}

}
int main() {
char letters[4] = { 'p','x','y','z' };
int index, count;
char z;
cout << "enter a letter : ";
cin >> z;
index = search(letters, 3, z);
cout << "index=" << index << endl;

return 0;
}
3. Write a program to split the odd and even numbers of one array into 2 arrays :

#include <iostream>

using namespace std;

int main()

int arr[10], even[10], odd[10], evncnt = 0, oddcnt = 0, i;

cout << "Input numbers in the array";

for (i = 0; i < 10; i++)

cin >> arr[i];

for (i = 0; i < 10; i++)

if (arr[i] % 2 == 0)

even[evncnt++] = arr[i];

else

odd[oddcnt++] = arr[i];

cout << "The even numbers are: ";

for (i = 0; i < evncnt; i++)

cout << even[i] << " ";

cout << "\nThe odd numbers are: ";

for (i = 0; i < oddcnt; i++)

cout << odd[i] << " ";

You might also like