Lee_assig22

# Lee_assig22 - cout<<a[j]<<"...

This preview shows pages 1–2. Sign up to view the full content.

Sheet1 Page 1 //Cheu Lee #include <iostream> #include <cmath> using namespace std int main() { int choice=0 i cout<<"What would you like to do? choose 1, 2, 3 or 4:\n" cout<<"+-------------------------------------------------+\n" cout<<"| 1. Find the smallest number & replace with 100 |\n" cout<<"| 2. Re-Arrange the values in the Array |\n" cout<<"| 3. Shift the values in the Array to the right |\n" cout<<"| 4. Exit |\n" cout<<"+-------------------------------------------------+\n" cin>>choice if(choice==1){ cout<<"The lowest will be replaced with 100"<<endl c int a[8]={-1, 2, 0, -5, 7, 4, 1, 7} int min=a[0] int index=0 for(int i=0 i<8 i++){ if(a[i]<min){ min=a[i] index=i } } a[index]=100 for(int j=0 j<8 j++){

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cout<<a[j]<<" "<<endl } return 0 } if(choice==2){ cout<<"The Array will re-arrange from smallest to largest"<<endl int a[8]={-1, 2, 0, -5, 7, 4, 1, 7} int min=a[0], t, index for (int i=0 i<8 i++) { if (a[i]<min) { min=a[i] index=i t=a[index] a[index]=a[0] a[0]=t } } cout<<endl Sheet1 Page 2 for (int p=0 p<8 p++) cout<<a[p]<<" "<<endl } if(choice==3){ cout<<"The numbers in the array will shift one to the right"<<endl int an[8]={-1, 2, 0, -5, 7, 4, 1, 7} int arry=an[0] for (int i=8 i>0 i--){ an[i+1]=an[i] } an[1]=arry for (int j=0 j<8 j++) cout<<an[j]<<" "<<endl } if (choice==4){ cout<<"You have chosen to exit the program"<<endl } return 0 }...
View Full Document

## This note was uploaded on 05/16/2010 for the course CISCO EST61 taught by Professor Miller during the Spring '10 term at Fresno City College.

### Page1 / 2

Lee_assig22 - cout<<a[j]<<"...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online