codinasion-archive / codinasion-monorepo

Community Monorepo
https://codinasion.org
MIT License
52 stars 170 forks source link

Write a C# program to find the smallest three elements in an array #5225

Open harshraj8843 opened 8 months ago

harshraj8843 commented 8 months ago

Description

Write a C# program to find the smallest three elements in an array

Input  : arr[] = {10, 4, 3, 50, 23, 90}
Output : 3 4 10

Input  : arr[] = {12, 13, 1, 10, 34, 1}
Output : 1 1 10
How to contribute - Comment `!assign` to assign this issue to yourself - Fork this repository - Create a new branch - Save the solution in `program/program/find-the-smallest-three-elements-in-an-array/FindTheSmallestThreeElementsInAnArray.cs` - Commit the changes - Create a pull request
codinasion-bot[bot] commented 8 months ago

👋🏻 Hey @harshraj8843

💖 Thanks for opening this issue 💖

A team member should be by to give feedback soon.

zackbmz commented 8 months ago

!assign

codinasion-bot[bot] commented 8 months ago

Hey @srivamsidandu, this issue is already assigned to @zackbmz! cc/ @codinasion/codinasion

Ruttviii commented 5 months ago

include

include

void moveZeroesToEnd(std::vector& nums) { int nonZeroIndex = 0;

// Iterate through the vector and move non-zero elements to the beginning
for (int num : nums) {
    if (num != 0) {
        nums[nonZeroIndex++] = num;
    }
}

// Fill the remaining elements with zeroes
while (nonZeroIndex < nums.size()) {
    nums[nonZeroIndex++] = 0;
}

}

int main() { std::vector nums = {0, 2, 0, 4, 0, 6, 8, 0, 10};

moveZeroesToEnd(nums);

std::cout << "Array after moving zeroes to the end:" << std::endl;
for (int num : nums) {
    std::cout << num << " ";
}
std::cout << std::endl;

    return 0; }