Write a Program in C That Shifted, Scaled Random Integers Produced by 1 + Rand() % 6

// Shifted, scaled random integers produced by 1 + rand() % 6.
#include <stdio.h>
#include <stdlib.h>

// function main begins program execution
int main( void )
{
   unsigned int i; // counter
   
   // loop 20 times
   for ( i = 1; i <= 20; ++i ) {
  
      // pick random number from 1 to 6 and output it
      printf( "%10d", 1 + ( rand() % 6 ) );

      // if counter is divisible by 5, begin new line of output
      if ( i % 5 == 0 ) {
         puts( "" );
      } // end if
   } // end for
} // end main

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...