Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <time.h>
- using namespace std;
- int main()
- {
- srand(time(NULL));
- int array[30];
- int low=31, high=0, hold=0;
- float total=0, count=0, average=0;
- cout<<"Temperatures for this month: ";
- for(int c=0;c<30;c++)
- {
- array[c]=rand()%30+1;
- count++;
- cout<<array[c]<<", ";
- if(array[c]>high)high=array[c];
- if(array[c]<low)low=array[c];
- total+=array[c];
- }
- cout<<endl;
- cout<<"The highest temperature was: "<<high<<endl;
- cout<<"The lowest temperature was: "<<low<<endl;
- average=total/count;
- cout<<"The average temperature was: "<<average<<endl;
- for(int c=0;c<30;c++)
- {
- for(int x=0;x<29;x++)if(array[x]>array[x+1])
- {
- hold=array[x];
- array[x]=array[x+1];
- array[x+1]=hold;
- }
- }
- cout<<"Numbers in ascending order: ";
- for(int c=0;c<30;c++)cout<<array[c]<<", ";
- for(int c=0;c<30;c++)
- {
- for(int x=0;x<29;x++)if(array[x]<array[x+1])
- {
- hold=array[x];
- array[x]=array[x+1];
- array[x+1]=hold;
- }
- }
- cout<<endl;
- cout<<"Number is descending order: ";
- for(int c=0;c<30;c++)cout<<array[c]<<", ";
- }
Add Comment
Please, Sign In to add comment