0% found this document useful (0 votes)
24 views

Arrays Program

The document contains C++ code to perform three array operations: replace an element, sort the array, and delete an element. The replace code allows the user to enter the size of an array, populate it with values, then replace one element by entering its index and new value. The sort code populates an array, then uses a bubble sort algorithm to sort the values. The edit code populates an array, displays it, then allows deleting an element by entering its index.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Arrays Program

The document contains C++ code to perform three array operations: replace an element, sort the array, and delete an element. The replace code allows the user to enter the size of an array, populate it with values, then replace one element by entering its index and new value. The sort code populates an array, then uses a bubble sort algorithm to sort the values. The edit code populates an array, displays it, then allows deleting an element by entering its index.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

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; }

You might also like