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.
program TongN;
var
n, i, tong: integer;
begin
tong := 0;
writeln('Nhap so nguyen duong N: ');
readln(n);
i := 0;
while i < n do
begin
i := i + 1;
tong := tong + i;
end;
writeln('Tong cac so tu 1 den ', n, ' la ', tong);
readln;
end.
Bài 1:
uses crt;
var n,i,s:integer;
begin
clrscr;
write('Nhap n='); readln(n);
s:=0;
i:=1;
while i<=n do
begin
s:=s+i;
inc(i);
end;
writeln('Tong cac so trong khoang tu 1 den ',n,' la: ',s);
readln;
end.
Bài 2:
uses crt;
var n,i,s:integer;
begin
clrscr;
write('Nhap n='); readln(n);
s:=0;
i:=1;
while i<=n do
begin
s:=s+i;
i:=i+2;
end;
writeln('Tong cac so le trong khoang tu 1 den ',n,' la: ',s);
readln;
end.
Var a:array[1..15] of integer;
i,s:integer;
Begin
I:=1;
While i<=15 do
Begin
Write('Nhap phan tu thu ',i,' = ');readln(a[i]);
s:=s+a[i];
i:=i+1;
End;
Write('Tong la ',s);
Readln;
End.
Câu 1:
uses crt;
var s,i,n:integer;
begin clrscr;
s:=0;
write('Nhap n: ');readln(n);
for i:=1 to n do
if i mod 2 <> 0 then inc(s,i);
write('Tong cac so le tu 1 den ',n,' la: ',s);
readln
end.
Câu 2:
uses crt;
var s,i,n:integer;
begin clrscr;
s:=0;
write('Nhap n: ');readln(n);
for i:=1 to n do
if i mod 2 = 0 then inc(s,i);
write('Tong cac so le tu 1 den ',n,' la: ',s);
readln
end.
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.
Câu 1:
program Tinhtong:
var
n, i, sum: integer;
begin
write('Nhap n: ');
readln(n);
sum := 0;
for i := 2 to n do
begin
if i mod 2 = 0 then
begin
sum := sum + i;
end;
end;
writeln('Tong cac so chan tu 2 toi ', n, ' la ', sum);
readln;
end.
Câu 2:
program Tinhtong:
var
n, i, sum: integer;
begin
write('Nhap n: ');
readln(n);
sum := 0;
for i := 1 to n do
begin
if i mod 2 = 1 then
begin
sum := sum + i;
end;
end;
writeln('Tong cac so le tu 1 toi ', n, ' la ', sum);
readln;
end.
Bài 1:
uses crt;
var i,s:integer;
begin
clrscr;
s:=0;
for i:=10 to 50 do
if i mod 2=0 then s:=s+i;
writeln(s);
readln;
end.
Bài 2:
uses crt;
var a,i,n:integer;
begin
clrscr;
write('Nhap n='); readln(n);
a:=0;
for i:=1 to n do
a:=a+i*(i+2);
writeln(a);
readln;
end.
program TinhTongTich;
var
N, i, Tong, Tich:integer;
begin
writeln('Nhap so nguyen duong N:');
readln(N);
i:=1;
Tong:=0;
Tich:=1;
while i<=N do
begin
Tong:=Tong+i;
Tich:=Tich*i;
i:=i+1;
end;
writeln('Tong cac so tu 1 den ', N, ' la: ', Tong);
writeln('Tich cac so tu 1 den ', N, ' la: ', Tich);
readln;
end.
int main()
{
int n;
long s;
s=0;
i=1;
printf("\nSo n la: ");
scanf("%d",&n);
for(int i=1; i<=n; i++)
{
s=s+i;
}
printf("\nTổng %d là %ld: ", n, s);
}
Bài 1:
uses crt;
var n,i,t:integer;
begin
clrscr;
write('n='); readln(n);
t:=0;
i:=1;
while i<=n do
begin
t:=t+i;
i:=i+1;
end;
writeln('tong cac so nguyen tu 1 toi ',n,' la: ',t);
readln;
end.
Bài 2:
uses crt;
var n,t:longint;
begin
clrscr;
t:=0;
repeat
write('n='); readln(n);
t:=t+n;
until n=0;
writeln('tong cac so nguyen nhap tu ban phim la: ',t);
readln;
end.
Bài 3:
uses crt;
var d,i,t,n,x:longint;
a:array[1..100]of longint;
st:string;
begin
clrscr;
write('n='); readln(n);
str(n,st);
d:=length(st);
t:=0;
for i:=1 to d do
begin
val(st[i],a[i],x);
t:=t+a[i];
end;
writeln('tong cac chu so cua ',n,' la: ',t);
readln;
end.
Câu 1:
uses crt;
var n,i:integer;
tong:longint;
begin
clrscr;
write('Nhap n: ');readln(n);
i:= 0;
while i < n do
begin
i:= i + 1;
tong:= tong + i;
end;
write('Tong cac so tu 1 den ',n,'la: ',tong);
readln
end.
Câu 2:
uses crt;
var i,a:integer;
tong:longint;
begin
clrscr;
a:= 1; i:= 1; tong:= 0;
while a <> 0 do
begin
write('Nhap phan tu thu ',i,': ');
readln(a);
i:= i + 1;
tong:= tong + a;
end;
write('Tong cac so = ',tong);
readln
end.
Câu 3:
uses crt;
var n,luu,tong: integer;
begin
clrscr;
write('Nhap so N: ');readln(n);
luu:= n; tong:= n mod 10;
while (n div 10 > 0) do
begin
n:= n div 10;
tong:= tong + (n mod 10);
end;
write('Tong cac chu so cua so ',luu,' la: ',tong);
readln
end.