Add 'main.cpp' #1

Open
AliMehrabani wants to merge 1 commits from alimehrabani-patch-1 into master
  1. 23
      main.cpp

23
main.cpp

@ -0,0 +1,23 @@
#include <iostream> // Required for input/output operations (e.g., std::cout)
#include <cstdlib> // Required for rand() and srand() functions
#include <ctime> // Required for time() function to seed the random number generator
Review

A Comment

A Comment
int main() {
Review

Another Comment

Another Comment
Review

Another Comment

Another Comment
// Seed the random number generator using the current time.
// This ensures a different sequence of random numbers each time the program runs.
srand(static_cast<unsigned int>(time(0)));
// Generate a random number.
// rand() returns a pseudo-random integer in the range [0, RAND_MAX].
int randomNumber = rand();
// Generate a random number within a specific range (e.g., 0 to 99).
// The modulo operator (%) is used to limit the range.
int randomNumberInRange = rand() % 100;
// Print the generated random numbers.
std::cout << "A raw random number: " << randomNumber << std::endl;
std::cout << "A random number between 0 and 99: " << randomNumberInRange << std::endl;
return 0; // Indicate successful program execution
}
Loading…
Cancel
Save