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 <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>
#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;
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 sumOfOddElements(int arr[], int n) {
int sum = 0;
for(int i = 0; i < n; i++) {
if(arr[i] % 2 != 0) {
sum += arr[i];
}
}
return sum;
}
int main() {
int arr[] = {1, 2, 3, 4, 5};
int n = sizeof(arr) / sizeof(arr[0]);
int sumOfOdd = sumOfOddElements(arr, n);
cout << "Tong cac phan tu le cua mang la: " << sumOfOdd << 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;
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>
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;
}
#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;
}