Skip to content

Instantly share code, notes, and snippets.

@Jeremywu0109
Created December 7, 2019 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jeremywu0109/c970c93423e202465c384226a1626625 to your computer and use it in GitHub Desktop.
Save Jeremywu0109/c970c93423e202465c384226a1626625 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
int a[5]={0}, i = 0, x;
for (i = 0; i <= 4;i++)
{
cout << "Integer" << i+1 << ":";
cin >> x;
if(x>10||x<1)
{
i--;
continue;
}
a[i] = x;
}
cout << "Array:";
for (i = 0; i <= 4;i++)
{
cout << a[i];
if(i<4)
cout << " ";
}
cout << endl;
cout << "Reverse:";
for (i = 4; i >= 0; i--)
{
cout << a[i];
if(i>=1)
cout << " ";
}
cout << endl;
cout << "Arrayeven:";
for (i = 0; i <= 4;i++)
{
int r = 0;
if(a[i]%2==0)
{
cout << a[i];
r++;
}
while(r>0)
{
cout << " ";
r--;
}
}
cout << endl;
cout << "Arraysame:";
for (int i = 0; i <= 4;i++)
{
if(a[i]==i)
cout << a[i] << " ";
}
cout << endl;
cout << "Min:";
int key;
i = 0;
key = a[i];
for (i = 0; i < 4 ;i++)
{
if(a[i]>a[i+1])
key = a[i + 1];
}
cout << key;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment