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

Array Examples

The document contains two C++ programs. The first program reads ten integers from the user, finds the maximum and minimum values, and prints them. The second program reads five integers, calculates their sum, and prints the numbers in reverse order.

Uploaded by

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

Array Examples

The document contains two C++ programs. The first program reads ten integers from the user, finds the maximum and minimum values, and prints them. The second program reads five integers, calculates their sum, and prints the numbers in reverse order.

Uploaded by

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

// max and min by array

#include <iostream>
using namespace std;

int main ()
{ const int a=10;
int array[a],max=array[0],min;

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


{
cout<<"Enter element "<<i+1<<": "<<endl;
cin>>array[i];
}
// Find maximun and minimum number in array
for (int i=0; i<a; i++)
{
if (array[i]>max)
max=array[i];
}

min=max;
for (int i=0; i<a; i++)
{
if (array[i]<min)
min=array[i];
}
// Print the max and min numbers
cout<<"\n Maximum number is ="<< max<<endl;
cout<<"\n Minimum number is ="<< min<<endl;

return 0;
}

//Program to read five numbers, find their sum, and


//print the numbers in reverse order.
#include <iostream>
using namespace std;
int main()
{
int item[5]; //Declare an array item of five components
int sum;
int counter;
cout << "Enter five numbers: ";
sum = 0;
for (counter = 0; counter < 5; counter++)
{
cin >> item[counter];
sum = sum + item[counter];
}
cout << endl;
cout << "The sum of the numbers is: " << sum << endl;
cout << "The numbers in reverse order are: ";

//Print the numbers in reverse order.


for (counter = 4; counter >= 0; counter--)
cout << item[counter] << " ";
cout << endl;
return 0;
}

You might also like