Viết ct pascal nhập 1 dãy số nguyên gồm n phần tử .in ra màn hình tổng các số lẻ trong mảng ..... Mong Mn Giúp E Cho E Thi Hk ạ
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ạn tham khảo
uses crt;
var a:array[1..200]of integer;
i,n,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
for i:=1 to n do
if a[i] mod 2=0 then t:=t+a[i];
writeln(t);
readln;
end.
program im_14424;
uses crt;
var A: array[1..9999999] of interger;
S,P : integer;
i,n: byte;
begin
clrscr;
S:=0;
P:=0;
for i:=1 to n do
begin
write('Nhap vao phan tu thu: ',i,);
readln(A[i]);
S:=S+A[i]
P:=P*A[i]
end;
writeln(S);
write(P);
readln;
end.
program TongSoChiaHetCho5;
var
n, i, x, tong: integer;
begin
write('Nhap so phan tu n: ');
readln(n);
tong := 0;
for i := 1 to n do
begin
write('Nhap phan tu thu ', i, ': ');
readln(x);
if (x > 0) and (x mod 5 = 0) then
tong := tong + x;
end;
writeln('Tong cac so lon hon 0 va chia het cho 5 la: ', tong);
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;
}
Câu 1:
uses crt;
var a:array[1..200]of integer;
i,n,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
for i:=1 to n do
if a[i] mod 2=0 then t:=t+a[i];
writeln(t);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long a[1000],n,i,dem1,dem2;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
for (i=1; i<=n; i++) cout<<a[i]<<" ";
cout<<endl;
dem1=0;
dem2=0;
for (i=1; i<=n; i++)
{
if (a[i]%2==0) dem1++;
else dem2++;
}
cout<<dem1<<" "<<dem2;
return 0;
}
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.
Bài 1
Var a:array:[1..99] of integer;
i,n:integer;
s:longint;
Begin
Repeat
Write('n = ');readln(n);
Until (n > 0) and (n < 100);
For i:=1 to n do
Begin
Write('Nhap diem thu ',i,' = ');readln(a[i]);
if a[i] mod 2 = 0 then s:=s+a[i];
End;
Write('Cac so vua nhap la: ');
For i:=1 to n do
Write(a[i]:8);
writeln;
write('Tong cac so chan la ',s);
Readln
End.
Bài 2
Var a:array:[1..99] of integer;
i,n:integer;
s:longint;
Begin
Repeat
Write('n = ');readln(n);
Until (n > 0) and (n < 100);
For i:=1 to n do
Begin
Write('Nhap diem thu ',i,' = ');readln(a[i]);
if a[i] mod 2 <> 0 then s:=s+a[i];
End;
Write('Cac so vua nhap la: ');
For i:=1 to n do
Write(a[i]:8);
writeln;
write('Tong cac so le la ',s);
Readln
End.
program chuong_trinh;
uses crt;
var n,i,tong:integer;
a: array[1..1000] of integer;
begin
clrscr;
writeln('Nhap so phan tu cua day: ');readln(n);
writeln('Nhap ',n,' phan tu cua day: ');
for i:= 1 to n do readln(a[i]);
tong:=0;
for i:= 1 to n do if a[i] mod 2 = 1 then tong:=tong+a[i];
writeln('Tong cac so le trong mang la: ',tong);
readln
end.