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.

Bài 1: 

function canbac2(x:longint):real;

begin

canbac2:=sqrt(x);

end;

Bài 2: 

function tong(n:longint):longint;

var s,i:longint;

begin

s:=0;

for i:=1 to n do 

  s:=s+i;

tong:=s;

end;

20 tháng 12 2020

uses crt;

var n,i,s:integer;

begin

clrscr;

repeat

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

until n>0;

s:=0;

for i:=1 to n do

s:=s+i;

writeln('Ket qua la: ',s);

readln;

end.

14 tháng 11 2021

Bài 3: 

#include <bits/stdc++.h>
using namespace std;
long long n,i,t;
int main()
{
    cin>>n;
    t=0;
    for (i=1; i<=sqrt(n); i++)
        if (i==n/i) t=t+i;
else t=t+i+n/i;
    if (t==n) cout<<"Day la so hoan hao";
    else cout<<"Day khong la so hoan hao";
    return 0;
}

 

uses crt;

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

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

begin

clrscr;

readln(n);

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

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

writeln;

writeln('Cac so duong la: ');

for i:=1 to n do if (a[i]>0) then write(a[i]:4);

writeln;

t:=0;

for i:=1 to n do 

  if a[i] mod 3=0 then t:=t+a[i];

writeln(t);

for i:=1 to n-1 do 

  for j:=i+1 to n do

if a[i]<a[j] then

begin

tam:=a[i];

a[i]:=a[j];

a[j]:=tam;

end;

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

readln;

end.

1 tháng 3 2021

Program HOC24;

var n,i: integer;

s: longint;

begin

write('Nhap N: '); readln(n);

s:=2021;

for i:=0 to n do s=s+(2*i+1);

write('S= ',s);

readln

end.

*Cách 2: Dùng While do

uses crt;

var s,i,n:integer;

begin

clrscr;

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

s:=2021;

i:=0;

while i<=n do 

  begin

s:=s+(2*i+1);

i:=i+1;

end;

writeln(s);

readln;

end.

#include <bits/stdc++.h>

using namespace std;

long long a[10000],i,n;

int main()

{

cin>>n;

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

for (i=1; i<=n; i++) cout<<a[i]<<"     ";

cout<<endl;

t=0;

for (i=1; i<=n; i++) if (a[i]%2==0) t+=a[i];

cout<<"Tong cac so chan la: "<<t<<endl;

sort(a+1,a+n+1);

cout<<"Day so giam dan la: ";

for (i=n; i>=1; i--) cout<<a[i]<<" ";

return 0;

}

25 tháng 2 2022

Nhưng mà cái này dùng theo pascal và theo kiểu mảng ạ