Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<cstdlib>
- #include<cmath>
- using namespace std;
- int main()
- {
- const int size =5;
- double t, array[size]={5,0,3,6,1};
- const int sizZ=10;
- double a[sizZ];
- cout<<"\nSo your problem is, that you have the \n array[5] \n and a[10]"<<endl;
- cout<<"\n array[5] has cell index 0-4 an you did define values \n and a[10] has cell index 0-9 (values not defined yet)"<<endl;
- cout<<"\nLets print it - you would see it is undefined"<<endl;
- cout<<"\na[i]\t"<<"array[i]"<<endl;
- for (int i=0;i<=sizZ;i++) {
- cout<<a[i]<<"\t";
- cout<<array[i]<<"\n";
- }
- for (int i=0;i<size;i++){
- for (int k=0;k<size-1;k++){
- if(array[k]<array[k+1]){
- t=array[k+1];
- array[k+1]=array[k];
- array[k]=t;
- }
- }
- }
- cout<<"\nPart A"<<endl;
- for (int i=0;i<5;i++) {
- a[i]=array[i];
- cout<<a[i]<<" ";
- }
- cout<<"\nPart B "<<endl;
- for (int i=0;i<size;i++){
- for (int k=0;k<size-1;k++){
- if(array[k]>array[k+1]){
- t=array[k+1];
- array[k+1]=array[k];
- array[k]=t;
- }
- }
- }
- cout<<"\nPart C"<<endl;
- cout<<endl;
- cout<<"\n You assign to a[9]=array[9] a[8]=array[8] a[7]=array[7] a[6]=array[6] a[5]=array[5] "<<endl;
- cout<<"\n "<<endl;
- for (int i=9;i>=5;i--) {
- a[i]=array[i];
- cout<<i<<"\t"<<a[i]<<"\n";
- }
- cout<<"\nThe conclusion is that you are accesing a non-defined table incex, and you would get random results"<<endl;
- cout<<"\nyou should not read outside of table";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement