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.
a: Input: Dãy các số nguyên
Output: Tổng của dãy đó
c:
#include <bits/stdc++.h>
using namespace std;
long long x,n,i,t;
int main()
{
cin>>n;
t=0;
for (i=1; i<=n; i++)
{
cin>>x;
t=t+x;
}
cout<<t;
return 0;
}
Program HOC24;
var i,n: integer;
t: longint;
a: array[1..1000] of integer;
begin
write('Nhap n: '); readln(n);
for i:=1 to n do
begin
write('Nhap so thu ',i,': '); readln(a[i]);
end;
t:=0;
for i:=1 to n do if a[i] mod 2=0 then t:=t+a[i];
write('Tong cac so chan la: ',t);
readln
end.
uses crt;
var a:array[1..100]of integer;
i,n,t:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
for i:=1 to n do write(a[i]:4);
writeln;
t:=0;
for i:=1 to n do
if a[i]>0 then t:=t+a[i];
writeln(t);
readln;
end.
Bài 1
Var s,i:integer;
tb:real;
Begin
Write('Nhap n = ');readln(n);
i:=1;
s:=0;
While i<=n do
Begin
s:=s+i;
i:=i+1;
End;
tb:=s/n;
Writeln('Tong la ',s);
Write('Trung binh la ',tb:10:2);
Readln;
End.
Bài 2
Var i,n,souoc:integer;
Begin
Write('Nhap n = ');readln(n);
i:=1;
While i <= n do
Begin
i:=i + 1;
If n mod i = 0 then souoc:=souoc + 1;
End;
If souoc = 1 then write(n,' la so nguyen to')
Else write(n,' khong la so nguyen to');
Readln;
End.
Bài 1:
uses crt;
var a:array[1..100]of integer;
i,n:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
for i:=1 to n do
if a[i] mod 2<>0 then write(a[i]:4);
readln;
end.
Bài 2:
uses crt;
var a:array[1..100]of integer;
i,n:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
for i:=1 to n do
if a[i] mod 2=0 then write(a[i]:4);
readln;
end.
uses crt;
var a: array[1..100] of integer;
i,n,s,s1,s2,s3: integer;
begin
clrscr;
writeln(' nhap so phan tu cua day'); readln(n);
for i:=1 to n do
begin
writeln('a[',i,']'); readln(a[i]);
end;
write('day vua nhap la:');
s:=0;
for i:=1 to n do
begin
write(a[i],' ');
s:=s+a[i];
if a[i] mod 2=0 then s1:=s1+a[i];
if a[i] mod 2<>0 then s2:=s2+a[i];
if a[i] mod 3=0 then s3:=s3+a[i];
end;
writeln;
writeln('tong bang:',s);
writeln('tong chan:',s1);
writeln('tong le:',s2);
writeln('tong chia het cho 3:',s3);
readln
end.
Tham khảo
uses crt;
var a:array[1..500]of integer;
n,i,t:integer;
Begin
clrscr;
write('n = ');readln(n);
for i:=1 to n do
begin
write('a[',i,'] = ');readln(a[i]);
t:=t+a[i];
end;
write('tong = ',t);
readln
Uses crt;
var max,min,n,i,m,n: longint;
a: array[1..100] of longint
begin clrscr;
for i:=1 to n do begin
if(a[i] mod 2=0) then m:=m+a[i];
if(a[i] mod 2<>0) then n:=n+a[i];
end;
max:=a[1];
min:=a[1];
for i:=1 to n do begin
if(max<a[i]) then max:=a[i];
if(min>a[i]) then min:=a[i];
end;
Writeln('Tong cac phan tu chan: ',m);
Writeln('Tong cac phan tu le: ',n);
Writeln('Phan tu co gia tri lon nhat: ',max);
Writeln('Phan tu co gia tri nho nhat: ',min);
readln;
end.
program tinhTong;
var
n,i,s: integer;
a: array[1..100] of integer;
begin
write('Nhap so luong phan tu: ');
readln(n);
for i := 1 to n do
begin
write('a[',i,'] = ');
readln(a[i]);
end;
s := 0;
for i := 1 to n do
begin
if (a[i] mod 5 <> 0) then
s := s + a[i];
end;
writeln('Tong cac so khong chia het cho 5: ', s);
readln;
end.
program TinhTong;
var
n, i, s, x: integer;
begin
write('Nhap so luong phan tu cua day: ');
readln(n);
s := 0;
for i := 1 to n do
begin
write('Nhap phan tu thu ', i, ': ');
readln(x);
if (x mod 5 <> 0) then
s := s + x;
end;
writeln('Tong cac so khong chia het cho 5 la: ', s);
end.