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.
1:
uses crt;
var n,i,t:integer;
begin
clrscr;
readln(n);
t:=0;
for i:=1 to n do
t:=t+i*i;
write(t);
readln;
end.
2
program bt2;
var i,n,t:integer;
begin
readln(n);
s:=0;
for i:=1 to n do
if i mod 2 = 1 then s:=s+i;
readln;
end.
Bài 1:
uses crt;
var n,i,s:integer;
begin
clrscr;
write('Nhap n='); readln(n);
s:=0;
for i:=1 to n do
if i mod 6=0 then s:=s+i;
writeln(s);
readln;
end.
Bài 2:
uses crt;
var a,b,c,ucln,i:integer;
begin
clrscr;
write('a='); readln(a);
write('b='); readln(b);
write('c='); readln(c);
while a<>b do
begin
if a>b then a:=a-b
else b:=b-a;
end;
ucln:=a;
while ucln<>c do
begin
if ucln>c then ucln:=ucln-c
else c:=c-ucln;
end;
writeln(ucln);
readln;
end.
program TongN;
var
n, i, Tong: integer;
begin
writeln('Nhap so nguyen n:');
readln(n);
while(n<5) or (n>15) do
begin
writeln('Vui long nhap n nam trong khoang 5-15');
readln(n);
end;
Tong := 0;
for i:=1 to n do
Tong := Tong + i;
writeln('Tong cac so tu 1 den n: ', Tong);
readln;
end.
uses crt;var n: longint; chrn: string; valn,sum,max,i,preperror: byte;begin write('Nhap so can kiem tra: '); readln(n); str(n,chrn); for i:=1 to length(chrn) do begin val(chrn[i],valn,preperror); sum:=sum+valn; if max<valn then max:=valn; valn:=0 end; writeln('Ket qua: '); writeln(length(chrn)); writeln(sum); write(max); readln;end.uses crt;var n: longint; chrn: string; valn,sum,max,i,preperror: byte;begin write('Nhap so can kiem tra: '); readln(n); str(n,chrn); for i:=1 to length(chrn) do begin val(chrn[i],valn,preperror); sum:=sum+valn; if max<valn then max:=valn; valn:=0 end; writeln('Ket qua: '); writeln(length(chrn)); writeln(sum); write(max); readln;end.
Program HOC24;
var N:longint;
max,tg,t,d: integer;
Begin
write('Nhap N : '); readln(N);
max:=0;
while n<>0 do
begin
tg:=n mod 10;
d:=d+1;
t:=t+tg;
if tg>max then max:=tg;
n:=n div 10;
end;
writeln('So nguyen N co ',d,' chu so');
writeln('Tong cac chu so cua N la : ',t);
write('Chu so lon nhat cua N la :',max);
readln
end.
Cau 1:
Câu 2:
#include <bits/stdc++.h>
using namespace std;
long long n;
int main()
{
cin>>n;
if (n>0 && n%5==0) cout<<"Phai";
else cout<<"Khong phai";
}
Var a:array[1..1000] of integer;
i,n,d:integer;
sd,s:longint;
Begin
Write('n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap phan tu thu ',i,' = ');readln(a[i]);
s:=s+a[i];
End;
For i:=1 to n do
If a[i] > 0 then
Begin
d:=d+1;
sd:=sd+a[i];
End;
Writeln('Tong cac so vua nhap la ',s);
Write('Co ',d,' so nguyen duong va tong cua chung la ',sd);
Readln
End.
uses crt;
var a:array[1..100]of integer;
i,n,dem1,dem2:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
dem1:=0;
dem2:=0;
for i:=1 to n do
begin
if a[i]>0 then inc(dem1);
if a[i]<0 then inc(dem2);
end;
writeln('So so nguyen duong la: ',dem1);
writeln('So so nguyen am la: ',dem2);
readln;
end.
program TongChuSo;
var
n, sum: integer;
begin
write('Nhap n: ');
readln(n);
sum := 0;
while n > 0 do
begin
sum := sum + (n mod 10);
n := n div 10;
end;
writeln('Tong cac chu so cua n la: ', sum);
readln;
end.
program C1;
uses crt;
Var A:array[1..100] of Integer ;
Tc, Tl : Integer ;
n, i: Btybe ;
begin
clrscr ;
Write( ' nhap n: ' ) ; Readln(n) ;
For i:=1 to n do
begin
Write ( ' A[ ' ,i, '] = ' ) ; Readln (A[i]) ;
end ;
Tc: = 0 ; Tl: = 0 ;
For i: = 1 to n do
If A[i] mod 2=0 then Tc:=Tc+A[i]
else Tl:= Tl + A[i] ;
Writeln ( ' Tong so chan : ' ; Tc) ;
Writeln ( ' Tong so le : ' , Tl ) ;
readln ;
end.
python
n = int(input("Nhập số nguyên dương N: "))
found = False
for i in range(1, n//2+1):
sum = i
j = i + 1
while sum < n:
sum += j
j += 1
if sum == n:
found = True
start = i
end = j - 1
break
if found:
print(n, "có tổng của nhiều số nguyên dương liên tiếp:")
for k in range(start, end+1):
print(k, end=" ")
else:
print(n, "không có tổng của nhiều số nguyên dương liên tiếp.")