Arrays

Published on December 2016 | Categories: Documents | Downloads: 39 | Comments: 0 | Views: 234
of 1
Download PDF   Embed   Report

Comments

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

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close