Home › Forums › C Programming › I also need help..!
- This topic has 1 reply, 2 voices, and was last updated 15 years, 4 months ago by GWILouisaxwzkla.
Viewing 1 reply thread
- AuthorPosts
- July 21, 2009 at 5:28 am #2213MercedeSlempParticipant
our professor gave us an assignment:
“create a program that produces a random sequence of ten integers between 0 and 9 and displays the biggest and the smallest integers in the list afterwards.”i am not that familiar in programming..so I really need your help..!
- July 21, 2009 at 5:36 pm #3594GWILouisaxwzklaParticipant
could try:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566<br />/****************************************************************<br />* File Name : c:programstempCG.cpp<br />* Date : july,21,2009<br />* Comments : new project<br />* Compiler/Assembler : Visual C++ 6.0<br />* Modifications :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 12:05:56 a.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include <br />#include <br />#include <br />//#include <br />//#include <br />//#include <br /><br />const MAX_SIZE = 10;<br />const int MAX_NUMBERS = 10;<br />using namespace std;<br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br />int numbers [ MAX_SIZE ];<br />int i;<br />int smallest , largest;<br />i = 1;<br />srand ( time ( NULL ) ); //seed random number generator<br />numbers [ 0 ] = rand () % MAX_NUMBERS;<br />smallest = largest = numbers [ 0 ]; //set smallest and largest for comparison<br />//generate random numbers<br />while ( i < MAX_SIZE )<br />{<br />numbers [ i ] = rand () % MAX_NUMBERS;<br />if ( numbers [ i ] > largest )<br />largest = numbers [ i ];<br />else if ( numbers [ i ] < smallest )<br />smallest = numbers [ i ];<br />i ++;<br />}<br />cout << "array generated: " << endl;<br />i = 0;<br />while ( i < MAX_NUMBERS )<br />{<br />cout << numbers [ i ] << " ";<br />i ++;<br />}<br />cout << endl << endl;<br />cout << "largest number was " << largest << endl;<br />cout << "smallest number was " << smallest << endl;<br /><br />return 0 ;<br />}<br /><br /><br /><br />
- AuthorPosts
Viewing 1 reply thread
- The forum ‘C Programming’ is closed to new topics and replies.