Những câu hỏi liên quan
thik
Xem chi tiết
Phía sau một cô gái
3 tháng 4 2023 lúc 22:02

program Chan_Le;

var

     n, i: integer;

begin

     write('Nhap vao so nguyen N: ');

     readln(n);

     writeln('Cac so chan tu 1 den ', n, ' la:');

     for i := 2 to n do

     begin

          if i mod 2 = 0 then

          begin

               write(i, ' ');

          end;

     end;

     writeln;

     writeln('Cac so le tu 1 den ', n, ' la:');

     for i := 1 to n do

     begin

          if i mod 2 <> 0 then

          begin

               write(i, ' ');

          end;

     end;

     readln;

end.

Bình luận (0)
Nguyễn Hoàng Duy
4 tháng 4 2023 lúc 0:06

program Chan_Le;

var n, i: integer;

begin
  write('Nhap vao so nguyen n: ');
  readln(n);
  writeln('Cac so chan tu 1 den ',n, ' la: ');
  for i := 1 to n do
  begin
    if i mod 2 = 0 then
      write(i, ' ');
  end;
  writeln;
  writeln('Cac so le tu 1 den ', n, ' la: ');
  for i := 1 to n do
  begin
    if i mod 2 <> 0 then
      write(i, ' ');
  end;
  readln;
  end.

Bình luận (0)
Phan Thu
Xem chi tiết
dinhnguyentuhuy
Xem chi tiết
Nguyễn Lê Phước Thịnh
13 tháng 12 2020 lúc 17:15

uses crt;

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

i,n,t,kt,j:integer;

begin

clrscr;

write('Nhap n='); readln(n);

for i:=1 to n do

begin

write('A[',i,']='); readln(a[i]);

end;

writeln('Cac so vua nhap la: ');

for i:=1 to n do 

  write(a[i]:4);

writeln;

t:=0;

for i:=1 to n do 

  t:=t+a[i];

writeln('Tong cua day so la: ',t);

kt:=0;

for j:=2 to trunc(sqrt(t)) do 

  if t mod j=0 then 

    begin

kt:=1;

break;

end;

if kt=0 then writeln(t,' la so nguyen to')

else writeln(t,' khong la so nguyen to');

readln;

end.

Bình luận (1)
dinhnguyentuhuy
Xem chi tiết
Nguyễn Lê Phước Thịnh
13 tháng 12 2020 lúc 22:29

uses crt;

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

i,n,t,kt:integer;

begin

clrscr;

write('Nhap n='); readln(n);

for i:=1 to n do

begin

write('A[',i,']='); readln(a[i]);

end;

writeln('Cac so ban vua nhap la: ');

for i:=1 to n do 

write(a[i]:4);

writeln;

t:=0;

for i:=1 to n do

t:=t+a[i];

writeln('Tong cac so vua nhap la: ',t);

if t>=2 then 

begin

kt:=0;

for i:=2 to trunc(sqrt(t)) do 

  if t mod i=0 then 

begin

kt:=1;

break;

end;

 if kt=0 then writeln(t,' la so nguyen to')

else writeln(t,' khong la so nguyen to');

end

else writeln(t,' khong la so nguyen to');

readln;

end.

Bình luận (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.

Bình luận (0)
Kỳ AnH
Xem chi tiết
khánh băng
Xem chi tiết
Nguyễn Lê Phước Thịnh
28 tháng 2 2023 lúc 22:35

uses crt;

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

i,n,dem,kt,j:integer;

begin

clrscr;

readln(n);

for i:=1 to n do write(i:4);

writeln;

for i:=2 to n do

begin

kt:=0;

for j:=2 to i-1 do 

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

if kt=0 then write(i:4);

end;

readln;

end.

Bình luận (0)
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;

}

Bình luận (0)
Nguyễn Trần Hồng Ngọc
Xem chi tiết
Phía sau một cô gái
7 tháng 5 2023 lúc 20:02

program TinhTBCTimSoNT;

var
  ten, lop: string;
  n, i, tong, dem: integer;
  A: array [1..11] of integer;
  trung_binh: real;

function LaSoNguyenTo(x: integer): boolean;
var
  i: integer;
begin
  if x < 2 then
    LaSoNguyenTo := false
  else if x = 2 then
    LaSoNguyenTo := true
  else if x mod 2 = 0 then
    LaSoNguyenTo := false
  else
  begin
    i := 3;
    while (i <= trunc(sqrt(x))) and (x mod i <> 0) do
      i := i + 2;
    LaSoNguyenTo := x mod i <> 0;
  end;
end;

begin
  // Nhập tên và lớp của học sinh
  write('Nhập tên của học sinh: ');
  readln(ten);
  write('Nhập lớp: ');
  readln(lop);

  // Nhập dãy số nguyên và tính trung bình cộng
  repeat
    write('Nhập số phần tử của dãy số (n<12): ');
    readln(n);
  until n < 12;
  tong := 0;
  for i := 1 to n do
  begin
    write('Nhập phần tử thứ ', i, ': ');
    readln(A[i]);
    tong := tong + A[i];
  end;
  trung_binh := tong / n;

  // In tên, lớp, dãy số và trung bình cộng ra màn hình
  writeln('Học sinh: ', ten);
  writeln('Lớp: ', lop);
  write('Dãy số: ');
  for i := 1 to n do
    write(A[i], ' ');
  writeln;
 
  // In các số nguyên tố của dãy số ra màn hình
  writeln('Các số nguyên tố của dãy số:');
  for i := 1 to n do
    if LaSoNguyenTo(A[i]) then
      writeln(A[i]);
end.

Bình luận (0)
nam bảo
Xem chi tiết
Nguyễn Lê Phước Thịnh
24 tháng 2 2022 lúc 13:44

uses crt;

var n,m,i,dem,t,t1,d1:integer;

//chuongtrinhcon

function ktnt(var n:integer):boolean;

var i:integer;

kt:boolean;

begin

kt:=true;

for i:=2 to trunc(sqrt(n)) do 

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

if (kt=true) then ktnt:=true

else ktnt:=false;

end;

//chuongtrinhchinh

begin

clrscr;

readln(n,m);

if (ktnt(n)=true) then writeln(n,' la so nguyen to')

else writeln(n,' ko la so nguyen to');

dem:=0;

t:=0;

for i:=2 to n do 

  if (ktnt(i)=true) then

begin

write(i:4);

t:=t+i;

dem:=dem+1;

end;

writeln;

writeln(t,' ',dem);

t1:=0;

d1:=0;

for i:=n to m do 

  if ktnt(i)=true then

begin

write(i:4);

t1:=t1+i;

inc(d1);

end;

writeln;

writeln(t1,' ',d1);

readln;

end.

Bình luận (0)