Skip to content

Commit c64882d

Browse files
committed
Generate MD files from code
1 parent b55c46e commit c64882d

2 files changed

Lines changed: 123 additions & 0 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
extension: cpp
3+
author: Kasa1905
4+
category: Algorithms
5+
layout: '../../layouts/SubmissionLayout.astro'
6+
title: Finding_missing_Element_from_a_range
7+
---
8+
```cpp
9+
#include <iostream>
10+
#include <vector>
11+
#include <algorithm>
12+
using namespace std;
13+
14+
// Function to find and print missing
15+
// elements in the given range
16+
void findMissing(int arr[], int n, int low, int high) {
17+
// Loop through the range of numbers from low to high
18+
for (int i = low; i <= high; i++) {
19+
bool found = false;
20+
21+
// Loop through the array to check if i exists in it
22+
for (int j = 0; j < n; j++) {
23+
if (arr[j] == i) {
24+
found = true;
25+
break;
26+
}
27+
}
28+
29+
// If i is not found in the array, print it
30+
if (!found) {
31+
cout << i << " ";
32+
}
33+
}
34+
}
35+
36+
// Driver's code
37+
int main() {
38+
int n, low, high;
39+
40+
// Taking input for the array size
41+
cout << "Enter the number of elements in the array: ";
42+
cin >> n;
43+
44+
vector<int> vec(n);
45+
46+
// Taking input for the array elements
47+
cout << "Enter the elements of the array: ";
48+
for (int i = 0; i < n; i++) {
49+
cin >> vec[i];
50+
}
51+
52+
// Taking input for the range
53+
cout << "Enter the low and high values of the range: ";
54+
cin >> low >> high;
55+
56+
// Convert vector to array
57+
int arr[n];
58+
copy(vec.begin(), vec.end(), arr);
59+
60+
// Function call
61+
findMissing(arr, n, low, high);
62+
63+
return 0;
64+
}```
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
extension: java
3+
author: Kasa1905
4+
category: Algorithms
5+
layout: '../../layouts/SubmissionLayout.astro'
6+
title: Finding_missing_element_from_a_range
7+
---
8+
```java
9+
import java.util.*;
10+
11+
public class Finding_missing_element_from_a_range {
12+
// Function to find and print missing elements in the given range
13+
static void findMissing(int[] arr, int n, int low, int high) {
14+
// Loop through the range of numbers from low to high
15+
for (int i = low; i <= high; i++) {
16+
boolean found = false;
17+
// Loop through the array to check if i exists in it
18+
for (int j = 0; j < n; j++) {
19+
if (arr[j] == i) {
20+
found = true;
21+
break;
22+
}
23+
}
24+
25+
// If i is not found in the array, print it
26+
if (!found) {
27+
System.out.print(i + " ");
28+
}
29+
}
30+
}
31+
32+
// Driver's code
33+
public static void main(String[] args) {
34+
Scanner scanner = new Scanner(System.in);
35+
36+
// Input for the size of the array
37+
System.out.print("Enter the number of elements in the array: ");
38+
int n = scanner.nextInt();
39+
int[] arr = new int[n];
40+
41+
// Input for the array elements
42+
System.out.println("Enter the elements of the array:");
43+
for (int i = 0; i < n; i++) {
44+
arr[i] = scanner.nextInt();
45+
}
46+
47+
// Input for the range
48+
System.out.print("Enter the low value of the range: ");
49+
int low = scanner.nextInt();
50+
System.out.print("Enter the high value of the range: ");
51+
int high = scanner.nextInt();
52+
53+
// Function call
54+
System.out.println("Missing elements in the range " + low + " to " + high + ":");
55+
findMissing(arr, n, low, high);
56+
57+
scanner.close();
58+
}
59+
}```

0 commit comments

Comments
 (0)