Code:#include <stdlib.h> #include <stdio.h> #include <string.h> #include <iomanip.h> #include <iostream.h> #include <time.h> #define DARR_LEN 5 void main() { double dArr[DARR_LEN]; long lArr[7]={100000, 134567, 123456, 9, -234567, -1, 123489}; int iArr[3][5]; char sName[30]="Andrew Dundas"; short cnt1, cnt2; long double total; long highest; srand(0); for(cnt1 = 0; cnt1 < DARR_LEN; cnt1++) { dArr[cnt1] = rand(); cout <<dArr[cnt1]<<" "; } cout <<endl; total = 0.0; for(cnt1 = 0; cnt1 < DARR_LEN; cnt1++) total += dArr[cnt1]; cout <<"Total is: "<< total <<endl; cout <<"Average is: "<< total/DARR_LEN <<endl; for ( cnt1 = 1, highest = lArr[0] ; cnt1 < 7 ; cnt1++ ) { if (lArr[cnt1] > highest) highest = lArr[cnt1]; } cout <<"The highest number is: "<<highest<<endl; srand( (unsigned) time(NULL)); for (cnt1 = 0; cnt1 < 3; cnt1++) { for(cnt2 = 0; cnt2 < 5;cnt2++) iArr[cnt1][cnt2] = rand()%49+1; } for (cnt1 = 0; cnt1 < 3; cnt1++) { cout<<"Row "<<cnt1+1<<": "; for(cnt2 = 0; cnt2 < 5;cnt2++) cout <<setw(3)<<iArr[cnt1][cnt2]; cout<<endl; } for (cnt1 = 0; cnt1 < 5; cnt1++) { cout<<"Column "<<cnt1+1<<": "; for(cnt2 = 0; cnt2 < 3;cnt2++) cout <<setw(3)<<iArr[cnt2][cnt1]; cout<<endl; } cout <<"Enter Name "; cin.getline(sName, 30); cnt1 = 0; while (sName[cnt1] != '\0') { cout << (int)sName[cnt1] <<endl; cnt1++; } strcpy(sName, "Albert Einstein"); cout << (int)sName[11]<<endl; //Define pointer to a double, pdArray. double *pdArray; //Assign the pointer, pdArray, to contain the address of the //double array, dArr. pdArray = dArr[DARR_LEN]; //Use the array name, dArr, to print out the array elements with //subscript notation, [ ]. cout << dArr[DARR_LEN]<<endl; //Use the pointer to print out the array elements with //pointer notation while not changing the pointer itself. //Use a for loop. for ( cnt1 = 0; cnt1 < 5; cnt1++, pdArray++) cout <<*pdArray<<" "; cout <<endl; //Use the pointer to print out the array elements with pointer //notation but change the //pointer to point to the actual array element rather than the //method in 18. for (cnt1 = 0; cnt1 < 5; cnt1++) cout <<*(pdArray+cnt1)<<" "; cout <<endl; //Use the array name for the double array and //pointer notation to print the entire array for (cnt1 = 0; cnt1 < 5; cnt1++) cout << *(dArr+cnt1)<<" "; cout<<endl; }
Code tags added by Hammer