Home Forums C Programming I also need help..!

Viewing 1 reply thread
  • Author
    Posts
    • #2213
      MercedeSlemp
      Participant

      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..!

    • #3594
      GWILouisaxwzkla
      Participant

      could try:


      /****************************************************************
      * File Name : c:programstempCG.cpp
      * Date : july,21,2009
      * Comments : new project
      * Compiler/Assembler : Visual C++ 6.0
      * Modifications :
      *
      *
      *
      *
      *
      * Program Shell Generated At: 12:05:56 a.m.
      =-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/


      #include
      #include
      #include
      //#include
      //#include
      //#include

      const MAX_SIZE = 10;
      const int MAX_NUMBERS = 10;
      using namespace std;

      //main function ******************************

      int main ( )
      {

      int numbers [ MAX_SIZE ];
      int i;
      int smallest , largest;
      i = 1;
      srand ( time ( NULL ) ); //seed random number generator
      numbers [ 0 ] = rand () % MAX_NUMBERS;
      smallest = largest = numbers [ 0 ]; //set smallest and largest for comparison
      //generate random numbers
      while ( i < MAX_SIZE )
      {
      numbers [ i ] = rand () % MAX_NUMBERS;
      if ( numbers [ i ] > largest )
      largest = numbers [ i ];
      else if ( numbers [ i ] < smallest )
      smallest = numbers [ i ];
      i ++;
      }
      cout << "array generated: " << endl;
      i = 0;
      while ( i < MAX_NUMBERS )
      {
      cout << numbers [ i ] << " ";
      i ++;
      }
      cout << endl << endl;
      cout << "largest number was " << largest << endl;
      cout << "smallest number was " << smallest << endl;

      return 0 ;
      }



Viewing 1 reply thread
  • The forum ‘C Programming’ is closed to new topics and replies.