Mine wont work Please help Requirements Compiles without wa

Mine wont work. Please help!

Requirements:

·         Compiles without warnings on omega using gcc and setting the std option to c89, and pedantic

·         Create an array of 100 randomly generated Natural Numbers

·         Sort the array of 100 randomly generated Natural Numbers in ascending order using bubble sort

·         Print the output 10 to a line with a width of 5

·         All work implemented in main function of program

Solution

#include <iostream>
#include <cstdlib>   
#include <ctime>
using namespace std;

int main()
{
int n = 100;
int a[n];
srand (time(NULL));
for(int i=0; i<n; i++){
a[i] = rand();
}
cout << \"Array elements before sorting: \" << endl;
for(int i=0; i<n; i++){
if(i % 10 == 0){
cout<<endl;
}
cout<<a[i]<<\" \";
  
}
cout<<endl;
int temp = 0;

for(int i=0; i < n; i++){
for(int j=1; j < (n-i); j++){

if(a[j-1] > a[j]){
//swap the elements!
temp = a[j-1];
a[j-1] = a[j];
a[j] = temp;
}

}
}
cout << \"Array elements after sorting: \" << endl;
for(int i=0; i<n; i++){
if(i % 10 == 0){
cout<<endl;
}
cout<<a[i]<<\" \";
  
}
cout<<endl;
return 0;
}

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                                                                                                                                                                

sh-4.2$ main                                                                                                                                                                                                                                                             

Array elements before sorting:                                                                                                                                                                                                                                           

                                                                                                                                                                                                                                                                         

100450255 449987459 1781583346 1977212214 1161716342 227913728 545422168 952672606 1700779626 548267365                                                                                                                                                                  

1207971597 53714351 1131408364 1765512979 1328179720 1855482025 1606534078 1922953664 1301070669 1607871929                                                                                                                                                              

354491619 1833352541 1266327517 2078455779 1778744593 578888039 1601203560 654190721 134429611 1185008990                                                                                                                                                                

1732954198 234879866 1634996450 1367053897 64608432 649229144 1594967625 610030600 1601901750 1148263603                                                                                                                                                                 

1158297965 662389699 1201977955 142222681 280419030 382674027 1997704706 1886953108 158144043 1151291727                                                                                                                                                                 

1347341389 512635663 837160621 466185258 443607794 468421566 1045073298 2044811354 1122612287 1179502909                                                                                                                                                                 

1082336696 708082838 1414382775 569849498 2075136735 1478991207 1219078642 1522620712 2089021808 673496744                                                                                                                                                               

523400668 1099836125 1335886443 1725378623 1242058807 1616305473 2108052650 1092279865 1355774934 118713046                                                                                                                                                              

96087945 555632675 631348709 933248566 1021817934 1074956503 1401670132 2066891232 972284209 376798772                                                                                                                                                                   

1098910493 2054620905 1084881610 365809620 476986756 1012534697 1844800827 1696065398 387671761 1786338987                                                                                                                                                               

Array elements after sorting:                                                                                                                                                                                                                                            

                                                                                                                                                                                                                                                                         

53714351 64608432 96087945 100450255 118713046 134429611 142222681 158144043 227913728 234879866                                                                                                                                                                         

280419030 354491619 365809620 376798772 382674027 387671761 443607794 449987459 466185258 468421566                                                                                                                                                                      

476986756 512635663 523400668 545422168 548267365 555632675 569849498 578888039 610030600 631348709                                                                                                                                                                      

649229144 654190721 662389699 673496744 708082838 837160621 933248566 952672606 972284209 1012534697                                                                                                                                                                     

1021817934 1045073298 1074956503 1082336696 1084881610 1092279865 1098910493 1099836125 1122612287 1131408364                                                                                                                                                            

1148263603 1151291727 1158297965 1161716342 1179502909 1185008990 1201977955 1207971597 1219078642 1242058807                                                                                                                                                            

1266327517 1301070669 1328179720 1335886443 1347341389 1355774934 1367053897 1401670132 1414382775 1478991207                                                                                                                                                            

1522620712 1594967625 1601203560 1601901750 1606534078 1607871929 1616305473 1634996450 1696065398 1700779626                                                                                                                                                            

1725378623 1732954198 1765512979 1778744593 1781583346 1786338987 1833352541 1844800827 1855482025 1886953108                                                                                                                                                            

1922953664 1977212214 1997704706 2044811354 2054620905 2066891232 2075136735 2078455779 2089021808 2108052650

Mine wont work. Please help! Requirements: · Compiles without warnings on omega using gcc and setting the std option to c89, and pedantic · Create an array of 1
Mine wont work. Please help! Requirements: · Compiles without warnings on omega using gcc and setting the std option to c89, and pedantic · Create an array of 1
Mine wont work. Please help! Requirements: · Compiles without warnings on omega using gcc and setting the std option to c89, and pedantic · Create an array of 1

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site