Hãy nhập câu hỏi của bạn vào đây, nếu là tài khoản VIP, bạn sẽ được ưu tiên trả lời.
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
const int maxN = 1e4 + 1;
int n, k, arr[maxN];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
for(int i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n);
cout << arr[k - 1];
}
Input:
7 4
29 847 1928 45 298 918219 38129
Output: 847
#include<bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int sum = 0;
for (int i = 1; i <= N; i++) {
if (sqrt(i) == (int)sqrt(i)) {
sum += i;
}
}
cout << sum << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
bool isPrime(int n) {
if(n <= 1) return false;
for(int i = 2; i <= sqrt(n); i++) {
if(n % i == 0) return false;
}
return true;
}
void printPrimes(int arr[], int n) {
for(int i = 0; i < n; i++) {
if(isPrime(arr[i])) {
cout << arr[i] << " la so nguyen to" << endl;
}
}
}
int main() {
int arr[] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
int n = sizeof(arr) / sizeof(arr[0]);
printPrimes(arr, n);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int findSecondLargest(int arr[], int n) {
sort(arr, arr + n, greater<int>());
return arr[1];
}
int main() {
int arr[] = {10, 20, 30, 40, 50};
int n = sizeof(arr) / sizeof(arr[0]);
int secondLargest = findSecondLargest(arr, n);
cout << "So lon thu hai trong mang la: " << secondLargest << endl;
return 0;
}
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
#include <bits/stdc++.h>
int main() {
int n;
cin>>n;
int sum=0;
for(int i=1;i<=n;i++)
{
sum+=i*i;
}
cout<<"The total is: "<<sum<<endl;
for(int j=0;j<=50000;j++)
{
int du=j%10;
int tongcacso=j%10*j%10*j%10;
cout<<"du="<<du<<endl;
sum=sum+du*du*du;
cout<<"\nsum= "<<sum<<endl;
cout<<"sum= (sum+j*j*j) "<<endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
void sortAscending(int arr[], int n) {
sort(arr, arr + n);
}
int main() {
int arr[] = {10, 5, 8, 7, 6};
int n = sizeof(arr) / sizeof(arr[0]);
sortAscending(arr, n);
for(int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
cout << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
void distinctElements(int arr[], int n) {
int i, j, count = 1;
sort(arr, arr + n);
for(i = 0; i < n - 1; i++) {
if (arr[i] != arr[i + 1]) {
count++;
out << arr[i] << " ";
}
}
cout << arr[n - 1] << " ";
cout << "\nSo phan tu khac nhau cua mang la: " << count << endl;
}
int main() {
int arr[] = {1, 2, 3, 4, 4, 5, 6, 6, 7, 7, 7, 8, 9, 9};
int n = sizeof(arr) / sizeof(arr[0]);
distinctElements(arr, n);
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
for (int i = 1; i <= 3; i++)
{
cin >> s;
cout << s << " ";
}
}
#include <iostream>
using namespace std;
int main() {
int num;
cout << "Nhap vao mot so nguyen co 2 chu so: ";
cin >> num;
int hang_chuc = num / 10;
int hang_don_vi = num % 10;
cout << "Chu so hang chuc: " << hang_chuc << endl;
cout << "Chu so hang don vi: " << hang_don_vi << endl;
return 0;
}