Những câu hỏi liên quan
Thảo Ngọc
Xem chi tiết
Trương Huy Hoàng
11 tháng 10 2021 lúc 22:32

#include <bits/stdc++.h>
using namespace std;
int diaphuong(int n) {
if (n<2) {
    return 0;
}
int squareRoot = (int) sqrt(n);
int i;
for(int i=2; i<=squareRoot; i++) {
    if(n%i==0) {
        return 0;
    }
}
    return 1;
}

int main() {
int i, N;
cin >> N;
for(int i=0; i<=N; i++) {
    if(diaphuong(i)) {
    cout << i << endl;
}
}
}

Chúc bn học tốt!

Uyen
Xem chi tiết
mistud
Xem chi tiết
Nguyễn Lê Phước Thịnh
10 tháng 12 2021 lúc 23:17

2:

#include <bits/stdc++.h>

using namespace std;

long long n,i;

int main()

{

cin>>n;

for (i=1; i<=n; i++)

if (n%i==0) cout<<i<<" ";

return 0;

}

Nguyễn minh tiến
Xem chi tiết
Nguyễn Lê Phước Thịnh
6 tháng 1 2022 lúc 10:25

#include <bits/stdc++.h>

using namespace std;

long long k,i;

int main()

{

cin>>k;

for (i=1; i<=k; i++) if (k%i==0) cout<<i<<" ";

return 0;

}

ksie
Xem chi tiết
Nguyễn Lê Phước Thịnh
20 tháng 1 2022 lúc 15:11

uses crt;

var n,i,dem,j,t:integer;

kt:boolean;

begin

clrscr;

readln(n);

t:=0;

for i:=2 to n do 

begin

kt:=true;

for j:=2 to i-1 do 

  if i mod j=0 then kt:=false;

if kt=true then 

begin

write(i:4);

t:=t+i;

end;

end;

writeln;

writeln(t);

readln;

end.

Minh Nhật Dương
Xem chi tiết
Nguyễn Lê Phước Thịnh
11 tháng 3 2022 lúc 9:13

uses crt;

var a:array[1..100]of integer;

i,n,j:integer;

kt:boolean;

begin

clrscr;

readln(n);

for i:=1 to n do readln(a[i]);

for i:=1 to n do 

 if trunc(sqrt(a[i]))=sqrt(a[i]) then write(a[i]:4);

writeln;

for i:=1 to n do 

 if a[i]>1 then 

begin

kt:=true;

for j:=2 to trunc(sqrt(a[i])) do

  if a[i] mod j=0 then kt:=false;

if kt=true then write(a[i]:4);

end;

writeln;

readln;

end.

Selena Flynn
Xem chi tiết
Nguyễn Lê Phước Thịnh
8 tháng 3 2022 lúc 23:03

c1: 

#include <bits/stdc++.h>

using namespace std;

long long i,n,s;

int main()

{

cin>>n;

s=1;

for (i=1; i<=n; i++) s=s*i;

cout<<s;

return 0;

}

Câu 2: 

#include <bits/stdc++.h>

using namespace std;

long long i,n,s;

int main()

{

cin>>n;

s=1;

for (i=1; i<=n; i++) if (i%2==0) s=s*i;

cout<<s;

return 0;

}

Linh Đan
Xem chi tiết
Võ Đức Dũng
17 tháng 9 2021 lúc 21:33

câu 1

Program Nguyen_to;

Var n,i:integer;

Function NT(n:integer):Boolean;

Var ok: Boolean;

i: integer;

Begin ok:=true;

for i:=2 to n-1 do if (n mod i)= 0 then ok:=ok and false;

if n < 2 then NT:=false else NT:=ok;

End;

Begin Write('Nhap n: ');

Readln(n); i:=n;

Repeat i:=i+1;

Until NT(i);

Write('So nguyen to nho nhat lon hon ',n, 'la: ',i);

Readln End.

Võ Đức Dũng
17 tháng 9 2021 lúc 21:39

câu 2

uses crt;

const so: set of char=['0','1','2','3','4','5','6','7','8','9'];

var a:array[1..100] of integer;

st,b:string;

c,l,i,n,j:integer;

s, Max: integer;

begin clrscr;

write('Nhap xau:');

readln(st);

l:=length(st);

i:=1;

n:=0;

repeat if (st[i] in so) then begin b:=''

repeat b:=b+st[i];

inc(i);

until (not(st[i] in so)) or (i>l);

inc(n);

val(b,a[n],c);

end;

inc(i);

until i>l;

Max:=a[1];

for i:=2 to n do If Max<A[i] Then Max:=A[i];

Writeln('Phan tu lon nhat cua mang:', Max);

readln;

end.

Phan Thu
Xem chi tiết