Arrays

of 1

Arrays

Content

REPLACING #include <iostream.h> main() { int x, num, arr[20], value, val; cout<<"Enter the number of element: "; cin>>num; for (x=1; x<=num; x++) { cout<< "Array " << x << ": "; cin>>arr[x]; } cout<< "The numbers are: "; for (x=1; x<=num; x++) { cout<< arr[x] << "\t"; } cout<< "\nEnter the subscript of the array you want to replace:"; cin>> value; cout<< "\nEnter the new value of the array:"; cin>>val; arr[value]=val; cout<< "Array: "; for (x=1; x<=num; x++) { cout<<arr[x]<< "\t"; } return 0; }

SORTING #include <iostream.h> main() { int x, num, arr[20], r, temp; cout<<"Enter the number of element: "; cin>>num; for (x=1; x<=num; x++) { cout<< "Array " << x << ": "; cin>>arr[x]; } for (x=0; x<num; x++) { for (r=0; r<num; r++) { if(arr[r]<=arr[r+1]) { temp=arr[r]; arr[r]=arr[r+1]; arr[r+1]=temp; } } } cout<< "\nSorted Arrays: "; for (x=1; x<=num; x++) { cout<<arr[x]<< "\t"; } return 0; }

EDIT #include <iostream.h> main() { int x, num, arr[20], value; cout<<"Enter the number of element: "; cin>>num; for (x=1; x<=num; x++) { cout<< "Array " << x << ": "; cin>>arr[x]; } cout<< "The numbers are: "; for (x=1; x<=num; x++) { cout<< arr[x] << "\t"; } cout<< "\nEnter the subscript of the array you want to delete:"; cin>> value; arr[value]=0; cout<< "Array: "; for (x=1; x<=num; x++) { cout<<arr[x]<< "\t"; } return 0; }

Recommended

Arrays

Or use your account on DocShare.tips

Hide