K
Khách

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.

17 tháng 9 2021

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.

17 tháng 9 2021

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.

22 tháng 1 2024

Program HOC24;

var x: integer;

begin

write('Nhap so: '); readln(x);

if x div 1000=1 then write('Mot nghin ');

if x div 1000=2 then write('Hai nghin ');

if x div 1000=3 then write('Ba nghin ');

if x div 1000=4 then write('Bon nghin ');

if x div 1000=5 then write('Nam nghin ');

if x div 1000=6 then write('Sau nghin ');

if x div 1000=7 then write('Bay nghin ');

if x div 1000=8 then write('Tam nghin ');

if x div 1000=9 then write('Chin nghin ');

if x div 1000<>0 then

if x div 100=0 then write('khong tram ');

if x div 100=1 then write('mot tram ');

if x div 100=2 then write('hai tram ');

if x div 100=3 then write('ba tram ');

if x div 100=4 then write('bon tram ');

if x div 100=5 then write('nam tram ');

if x div 100=6 then write('sau tram ');

if x div 100=7 then write('bay tram ');

if x div 100=8 then write('tam tram ');

if x div 100=9 then write('chin tram ');

if (x div 1000<>0) or (x div 100<>0) then

begin

if (x div 10<>0) then

begin

if x div 10=1 then write('muoi ');

if x div 10=2 then write('hai muoi ');

if x div 10=3 then write('ba muoi ');

if x div 10=4 then write('bon muoi ');

if x div 10=5 then write('nam muoi ');

if x div 10=6 then write('sau muoi ');

if x div 10=7 then write('bay muoi ');

if x div 10=8 then write('tam muoi ');

if x div 10=9 then write('chin muoi ');

if x mod 10=1 then write('mot');

if x mod 10=2 then write('hai');

if x mod 10=3 then write('ba');

if x mod 10=4 then write('bon');

if x mod 10=5 then write('lam');

if x mod 10=6 then write('sau');

if x mod 10=7 then write('bay');

if x mod 10=8 then write('tam');

if x mod 10=9 then write('chin');

end else

begin

if x mod 10=1 then write('le mot');

if x mod 10=2 then write('le hai');

if x mod 10=3 then write('le ba');

if x mod 10=4 then write('le tu');

if x mod 10=5 then write('le nam');

if x mod 10=6 then write('le sau');

if x mod 10=7 then write('le bay');

if x mod 10=8 then write('le tam');

if x mod 10=9 then write('le chin');

end;

readln

end.

#include <iostream>
using namespace std;
int main()
{
    int n,i,j;
    cout<<"Nhap n="; cin>>n;
    for (i=1; i<=n; i++)
    {
        for (j=i; j<=i+n-1; j++)
            cout<<j<<" ";
        cout<<endl;
    }
    return 0;
}

 

8 tháng 9 2021

#include <iostream>
using namespace std;
int main()
{
    int n,i,j;
    cout<<"Nhap n="; cin>>n;
    for (i=1; i<=n; i++)
    {
        for (j=i; j<=i+n-1; j++)
            cout<<j<<" ";
        cout<<endl;
    }
    return 0;
}

8 tháng 9 2021

#include <iostream>
using namespace std;
int main()
{
    int t,m,n,ucln;
    cout<<"Nhap n="; cin>>n;
    cout<<"Nhap m="; cin>>m;
    t=m%n;
    while (t!=0)
    {
        t=n%m;
        n=m;
        m=t;
    }
    ucln=n;
    cout<<ucln;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

long long a[100],n,i,ln,nn,vt1,vt2;

int main()

{

cin>>n;

for (i=1; i<=n; i++) cin>>a[i];

ln=a[1];

nn=a[1];

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

{

ln=max(ln,a[i]);

nn=min(nn,a[i]);

}

cout<<ln<<" "<<nn;

return 0;

}

19 tháng 1 2022

Var n,i,vtl,vtn,so max,min:integer;

Begin

Write('Nhap so luong so = ');readln(n);

vtl:=0;

vtn:=0;

max:=-32768;

min:=32767;

For i:=1 to n do

Begin

Write('Nhap vao so thu ',i);readln(so);

If so > max then

Begin

Max:=so;

vtl:=i;

End;

If so < min then

Begin

Min:=so;

vtn:=i;

End;

Writeln('So lon nhat la ',max,' tai vi tri thu ',i);

Write('So nho nhat la ',min,' tai vi tri thu ',i);

Readln;

End.

22 tháng 7 2023

program tong_so_le;

var

     n, i, a_i, tong: integer;

begin

     writeln('Nhap vao so nguyen khong am n:');

     readln(n);

     while (n <= 0) or (n > 100) do

     begin

          writeln('So nguyen n phai thoa man 0 < n <= 100, vui long nhap lai:');

          readln(n);

     end;

     writeln('Nhap vao ', n, ' so nguyen a1, a2, ..., an:','<mỗi số nguyên nhập trên một hàng>');

     tong := 0; // Khởi tạo tổng bằng 0

     for i := 1 to n do

     begin

          readln(a_i);

          if i mod 2 = 1 then

               tong := tong + a_i; 

     end;

     writeln('Tong cac so tai vi tri le trong mang la: ', tong);

end.

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.

14 tháng 9

cíu mik vs các bạn ơiT^T


14 tháng 9

Chung — thành phần cần tạo trong Scratch Biến: N, a, b, i, d, temp Danh sách (list): Digits (chứa các chữ số theo thứ tự đọc), Result (kết quả in ra) Khối (custom blocks / my blocks): Tách chữ số (N) — tách N ra list Digits theo thứ tự đọc (trái → phải) LàNguyênTố? (x) — trả về true/false (kiểm tra nguyên tố) In chữ số chẵn của N (hoặc In chữ số xuất hiện chẵn theo lựa chọn) In các số nguyên tố trong (a,b) Bạn dùng khối ask ... and wait để nhập số rồi set N to answer (chuyển sang số nếu cần: set N to (answer)). 1) In ra các chữ số có trong N (ví dụ 53211 → 5, 3, 2, 1, 1) Ý tưởng: Dùng phép chia lấy dư để lấy chữ số từ phải sang trái, lưu vào list tạm theo thứ tự ngược, rồi đảo lại để được thứ tự trái→phải. Các bước/kịch bản Scratch (blocks): Khi nhấn cờ xanh: ask Nhập số nguyên N: and wait set N to (answer) delete all of Digits run Tách chữ số (N) Khối Tách chữ số (N): set temp to (abs of N) // xử lý số âm bằng lấy trị tuyệt đối nếu cần if <(temp) = 0> then add 0 to Digits stop this script repeat until <(temp) = 0> set d to (temp mod 10) add d to Digits // đây là thứ tự ngược (1st = cuối cùng) set temp to (floor (temp / 10)) // bây giờ Digits chứa chữ số theo thứ tự ngược, cần đảo lại set i to 1 create a list DigitsReversed (hoặc reuse Result) delete all of Result repeat (length of Digits) add (item (length of Digits - i + 1) of Digits) to Result change i by 1 // hiển thị Result say (join Các chữ số: (join (item 1 of Result) , ...)) // hoặc lặp và in từng phần Ví dụ chạy: nhập 53211 → Result = [5,3,2,1,1] → hiển thị 5, 3, 2, 1, 1. 2) In ra các chữ số của N là số chẵn Như mình nói: ví dụ bạn đưa ra (53211 → 2 3) mâu thuẫn vì 3 lẻ. Mình trình bày 2 phiên bản — bạn chọn cái bạn muốn. 2A) Phiên bản A: “những chữ số chẵn trong N” (giải nghĩa thông thường) Ý tưởng: Từ list Digits (từ bài 1), kiểm tra từng phần: nếu (digit mod 2) = 0 thì thêm vào Result. Khối In chữ số chẵn của N: delete all of Result for i from 1 to (length of Digits) // dùng biến i set d to (item i of Digits) if <((d mod 2) = 0)> then add d to Result // hiển thị Result (nếu rỗng thì nói 'không có') Ví dụ: 53211 → Digits=[5,3,2,1,1] → Result=[2] → hiển thị 2. 2B) Phiên bản B: “In ra các chữ số xuất hiện chẵn lần trong N” (Interpretation nếu bạn muốn chữ số có số lần xuất hiện là chẵn — ví dụ chữ số xuất hiện 2,4,... lần) Ý tưởng: Đếm tần suất từng chữ số (0–9), nếu tần suất mod 2 = 0 và >0 thì in. Khối In chữ số xuất hiện chẵn: delete all of Result tạo mảng đếm Count0..Count9 — trong Scratch bạn có thể dùng 10 biến c0, c1, ..., c9 hoặc một list Counts index 1..10 tương ứng chữ số 0..9 set all counts to 0 for i from 1 to length of Digits set d to (item i of Digits) change item (d+1) of Counts by 1 // (d+1 vì list index bắt đầu 1) for k from 1 to 10 if <((item k of Counts) > 0) and (((item k of Counts) mod 2) = 0)> then add (k-1) to Result hiển thị Result Ví dụ với 53211: Counts: 5→1, 3→1, 2→1, 1→2 → chữ số có tần suất chẵn: 1 (vì xuất hiện 2 lần) → Result=[1]. 3) Kiểm tra N có phải số nguyên tố không và in kết quả Ý tưởng: nếu N < 2 → không phải. Kiểm tra chia hết từ i = 2 tới i*i ≤ N (dùng i*i vì Scratch không có sqrt mặc định). Khối LàNguyênTố? (x): if <x < 2> then return false set i to 2 repeat until <(i * i) > x> if <(x mod i) = 0> then return false change i by 1 return true Kịch bản chính: ask Nhập số N để kiểm tra nguyên tố: and wait set N to (answer) if LàNguyênTố? (N) then say (join N là số nguyên tố) else say (join N không phải số nguyên tố) Ví dụ: nhập 17 → 17 là số nguyên tố. Nhập 20 → 20 không phải số nguyên tố. 4) Nhập 2 số nguyên a,b. In ra các số nguyên tố trong (a, b) Ý tưởng: Lấy start = min(a,b), end = max(a,b). Lặp k từ start+1 đến end-1, kiểm tra LàNguyênTố?(k) và thêm vào Result. Kịch bản: ask Nhập a: and wait → set a to answer ask Nhập b: and wait → set b to answer set start to (min(a,b)) set end to (max(a,b)) delete all of Result set k to start + 1 repeat until <k > end - 1> if LàNguyênTố?(k) then add k to Result change k by 1 hiển thị Result (nếu rỗng thì say Không có số nguyên tố trong khoảng) Ví dụ: a=2, b=10 → in 3 5 7. Mẹo ráp khối trong Scratch (chi tiết tiện dùng) Dùng my block (Make a Block) để tạo Tách chữ số, LàNguyênTố? (x). Với LàNguyênTố? bạn có thể làm block có checkbox run without screen refresh để chạy nhanh hơn. Dùng list để chứa Digits và Result. Khi in nhiều số, bạn có thể tạo 1 chuỗi (string) nối các item bằng join để hiển thị gọn: Lặp i=1..length(Result): set output to (join output (join (item i of Result) )) rồi say output. Xử lý số âm: nếu muốn cho phép N âm, trước khi tách chữ số dùng temp = abs(N). Tóm tắt ngắn (bản để bạn copy nhanh vào Scratch) Tạo list Digits, Result, Counts (nếu cần). Tạo my block Tách chữ số (N) theo thuật toán chia dư. Tạo my block LàNguyênTố? (x) kiểm tra bằng i*i ≤ x. Viết các script chính dùng ask → gọi các block → hiển thị Result.

19 tháng 10 2021

#include <bits/stdc++.h>

using namespace std;

long n,i,dem,t;

int main()

{

cin>>n;

dem=0;

t=0;

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

if (n%i==0) 

{

dem++;

t=t+i;

}

cout<<dem<<" "<<t;

return 0;

}