viết chương trình nhặp vài một mẵn gồm n là một phần tử
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.
là 1ngôn ngữ lập trình cơ bản . Ngoài ra còn có ngôn ngư x lập trình(code) như java.....
- Bạn vào shop.olm.vn
- Đăng nhập tài khoản của bạn vào rồi thực hiện để đổi quà chứ không thể chuyển sang tiền mặt
const fi='docao13.inp';
fo='docao13.out';
var f1,f2:text;
a:array[1..100]of integer;
i,n:integer;
//chuongtrinhcon
function kq(x:integer):integer;
var t,k:integer;
begin
t:=0;
while (x>0) do
begin
k:=x mod 10;
t:=t+k;
x:=x div 10;
end;
kq:=t;
end;
//chuongtrinhchinh
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n);
for i:=1 to n do
read(f1,a[i]);
for i:=1 to n do
write(f2,kq(a[i]):4);
close(f1);
close(f2);
end.
#include <iostream>
#include <cmath>
using namespace std;
bool isPrime(int number) {
if (number < 2) {
return false;
}
for (int i = 2; i <= sqrt(number); i++) {
if (number % i == 0) {
return false;
}
}
return true;
}
int main() {
int N;
cin >> N;
int count = 0;
for (int i = 0; i < N; i++) {
int num;
cin >> num;
if (isPrime(num)) {
count++;
}
}
cout << "Số lượng số nguyên tố trong dãy là: " << count << endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int A[100],B[100],C[100],kt,n,nn,dem1=0, dem2=0;
int main()
{
cin>>n;
for (int i=1; i<=n; i++)
cin>>A[i];
kt=0;
nn=INT_MAX;
for (int i=1; i<=n; i++)
if (A[i]%2!=0)
{
kt=1;
if (nn>=A[i]) nn=A[i];
}
if (kt==0) cout<<"khong co";
else cout<<nn;
cout<<endl;
for (int i=1; i<=n; i++)
if (A[i]%2==0 && A[i]>7)
cout<<A[i]<<" ";
cout<<endl;
for (int i=1; i<=n; i++)
if (A[i]%2!=0)
{
dem1++;
B[dem1]=A[i];
}
for (int i=1; i<=n; i++)
if (A[i]%2==0)
{
dem2++;
C[dem2]=A[i];
}
sort(B,B+dem1+1);
sort(C,C+dem2+1);
for (int i=dem1; i>=1; i--)
cout<<B[i]<<" ";
for (int i=1; i<=dem2; i++)
cout<<C[i]<<" ";
}