0% found this document useful (0 votes)
22 views2 pages

Generate and Find Largest Random Number

This C++ program generates 10 random numbers between 1 and 100, stores them in a vector, and then identifies the largest number among them. It uses the current time to seed the random number generator. Finally, it prints the generated numbers and the largest number found.

Uploaded by

sohawe9511
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

Generate and Find Largest Random Number

This C++ program generates 10 random numbers between 1 and 100, stores them in a vector, and then identifies the largest number among them. It uses the current time to seed the random number generator. Finally, it prints the generated numbers and the largest number found.

Uploaded by

sohawe9511
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include <iostream>

#include <vector>

#include <cstdlib> // for rand()

#include <ctime> // for time()

// This program generates random numbers, stores them in a vector,

// then finds the largest number.

int main() {

// Seed the random generator using the current time

std::srand(std::time(0));

std::vector<int> numbers;

int count = 10; // how many random numbers to generate

// Generate random numbers from 1 to 100

for (int i = 0; i < count; i++) {

int num = std::rand() % 100 + 1;

numbers.push_back(num);

// Print the numbers

std::cout << "Random numbers: ";

for (int n : numbers) {

std::cout << n << " ";

std::cout << std::endl;


// Find the largest number manually

int largest = numbers[0];

for (int n : numbers) {

if (n > largest) largest = n;

// Show result

std::cout << "Largest number is: " << largest << std::endl;

return 0;

You might also like