es
Feedback
inactive

inactive

Canal cerrado
3 849
Suscriptores
Sin datos24 horas
-297 días
-12730 días
Archivo de publicaciones
#include <iostream> using namespace std; int findCrossOver(int arr[], int low, int high, int x) { if (arr[high] <= x) return high; if (arr[low] > x) return low; int mid = (low + high) / 2; if (arr[mid] <= x && arr[mid + 1] > x) return mid; if (arr[mid] < x) return findCrossOver(arr, mid + 1, high, x); return findCrossOver(arr, low, mid - 1, x); } void printKclosest(int arr[], int x, int k, int n) { int l = findCrossOver(arr, 0, n - 1, x); int r = l + 1; int count = 0; if (arr[l] == x) l--; while (l >= 0 && r < n && count < k) { if (x - arr[l] < arr[r] - x) cout << arr[l--] << " "; else cout << arr[r++] << " "; count++; } while (count < k && l >= 0) cout << arr[l--] << " ", count++; while (count < k && r < n) cout << arr[r++] << " ", count++; } int main() { int n; std::cin >> n; int* arr = new int[n]; for (int i = 0; i < n; i++) { std::cin >> arr[i]; } int x; cin >> x; int k; cin >> k; printKclosest(arr, x, k, n); delete[] arr; return 0; }

8 1 3 5 7 9 11 13 15 10

#include<iostream> #include<vector> using namespace std; int main() { int numArrays; cin >> numArrays; int mergedArray[10000]; int mergedIndex = 0; for (int i = 0; i < numArrays; ++i) { int arraySize; cin >> arraySize; for (int j = 0; j<arraySize; ++j) { int element; cin >> element; mergedArray[mergedIndex] = element; mergedIndex++; } } cout <<"Merged array: "; for(int k = 0; k < mergedIndex; ++k) { cout<<mergedArray[k]<< " "; } cout << endl; //awasthi return 0; }

Input 2 : 2 6 11 12 13 17 18 19 3 14 15 16

#include <iostream> int main() { const int MAX_SIZE = 100; int n; std::cin >> n; int arr[MAX_SIZE]; for (int i = 0; i < n; ++i) { std::cin >> arr[i]; } int newValue; std::cin >> newValue; std::cout << "Original array:"; for (int i = 0; i < n; ++i) { std::cout << " " << arr[i]; } std::cout << std::endl; for (int i = n - 1; i >= 0; --i) { arr[i + 1] = arr[i]; } arr[0] = newValue; std::cout << "Updated array:"; for (int i = 0; i <= n; ++i) { std::cout << " " << arr[i]; } std::cout << std::endl; return 0; }

5 8 -2 3 -4 6 4

// You are using GCC #include <iostream> #include <vector> //awasthi std::vector<double> filter_positive_prices(const std::vector<double>& closing_prices) { std::vector<double> positive_prices; for (double price : closing_prices) { if (price >= 0) { positive_prices.push_back(price); } } return positive_prices; } int main() { int n; std::cin >> n; std::vector<double> closing_prices(n); for (int i = 0; i < n; ++i) { std::cin >> closing_prices[i]; } std::vector<double> positive_prices = filter_positive_prices(closing_prices); std::cout<<"Updated Array with Positive Closing Prices: "; for (double price : positive_prices) { std::cout << price << " "; } return 0; }

Input 2 : 5 10.5 -5.2 8.7 -3.9 12.3

+5
prices of product.cpp0.01 KB

+9
insert specfic position (1).cpp0.01 KB

All Questions containing 6 will come then just find from there.
All Questions containing 6 will come then just find from there.

Note:Just search by Input number 2 first element.Just like 6 here....

To Copy Download Windows Powertoys from Microsoft Store..

lect 6 cod above

#include<iostream> #include<string> using namespace std; void insertionSortAndDisplay(string arr[],int n){ cout<<"Initial order: "; for(int i=0;i<n;i++){ cout<<arr[i]<<" "; } cout<<endl; for (int i=01;i<n;i++){ string key =arr[i]; int j=i-1; while(j>=0 && arr[j]>key){ arr[j+1]=arr[j]; j--; } arr[j+1]=key; cout<<"After Iteration "<<i<<": "; for(int k=0;k<n;k++){ cout<<arr[k]<<" "; } cout<<endl; } cout<<"Sorted order: "; for(int i=0;i<n;i++){ cout<<arr[i]<<" "; } cout<<endl; } int main(){ int n; cin>>n; string contacts[n]; for(int i=0;i<n;i++){ cin>>contacts[i]; } insertionSortAndDisplay(contacts,n); }

6 Apple Orange Carrot Banana Grapes Kiwi Insertion sort

#include<iostream> #include<iomanip> using namespace std; void insertionSort(double* arr,int n){ for(int i=1;i<n;i++){ double key=arr[i]; int j=i-1; while (j>=0 && arr[j]>key){ arr[j+1]=arr[j]; j--; } arr[j+1]=key; cout<<"After Iteration "<<i<<": "; for(int k=0;k<n;k++){ cout<<fixed<<setprecision(2)<<arr[k]<<" "; } cout<<endl; } } int main(){ int n; cin>>n; double* arr=new double[n]; for(int i=0;i<n;i++){ cin>>arr[i]; } cout<<"Initial order: "; for(int i=0;i<n;i++){ cout<<fixed<<setprecision(2)<<arr[i]<<" "; } cout<<endl; insertionSort(arr,n); cout<<"Sorted order: "; for(int i=0;i<n;i++){ cout<<fixed<<setprecision(2)<<arr[i]<<" "; } cout<<endl; delete []arr; }