Skip to content
Minsing Log
Go back

English Edition

An Algorithm That Returns the Largest Element Among All Elements in a C++ vector

Programming & CS

GOAT!

#include <iostream>
#include <vector>

int main() {
    // 총 5개의 integer 요소가 들어있는 vector 생성
    std::vector<int> numbers = {10, 20, 30, 40, 50};

    // 가장 큰 요소를 찾기 위한 변수 초기화
    int maxElement = numbers[0];

    // 모든 요소를 순회하면서 가장 큰 요소를 찾는 과정
    for (int i = 1; i < numbers.size(); ++i) {
        if (numbers[i] > maxElement) {
            maxElement = numbers[i];
        }
    }

    // 가장 큰 요소 출력
    std::cout << "가장 큰 요소: " << maxElement << std::endl;

    return 0;
}

![](/images/velog/2885fa54c57200e4.png)

Follow the journey

Get new posts by email.

Short, honest notes on building, startups, learning, failures, and retrospectives, for readers who follow the journey rather than pass through from search.

The newsletter is coming soon. Until then, follow via RSS or email me to get notified.


Share this post:

Comments

Sign in with GitHub to leave a comment.


Previous Post
When you're frustrated because you still don't understand it after searching for the algorithm, don't fucking use a library
Next Post
Algorithm for deleting C++ vector elements without the algorithm library