Cho tệp SONGUYEN.INP chứa dãy số nguyên bất kì. Viết ct tính tổng các số chẵn trong dãy và in kết quả ra mh.
cho tệp SONGUYEN.INP, chứa một dãy số nguyên bất kì:
Viết chương trình pascal: Tính tổng các số chẵn trong dãy số nguyên đó. kết quả ghi vào tệp TONG.OUT.
const fi='songuyen.inp'
fo='tong.out'
var f1,f2:text;
a:array[1..100]of integer;
i,n,t:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
n:=0;
while not eoln(f1) do
begin
n:=n+1;
read(f1,a[n]);
end;
t:=0;
for i:=1 to n do
if a[i] mod 2=0 then t:=t+a[i];
writeln(f2,t);
close(f1);
close(f2);
end.
cho tệp songuyen.inp chứa dãy các số nguyên ( mỗi số cách nhau một dấu cách). Đọc dữ liệu từ tệp đã cho và
a) Tính tổng các số lẻ trong tệp và đưa kết quả lên màn hình.
b) tính tổng các số lẻ trong tệp và ghi kết quả vào tệp songuyen2
c) đưa ra màn hình các số lẻ trong tệp
uses crt;
const fi='songuyen.inp'
fo='songuyen2.out'
var a:array[1..100]of integer;
i,n,t1:integer;
f1,f2:text;
begin
clrscr;
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n);
for i:=1 to n do readln(f1,a[i]);
t1:=0;
for i:=1 to n do if a[i] mod 2<>0 then t1:=t1+a[i];
writeln(t1);
writeln(f2,t1);
for i:=1 to n do
if a[i] mod 2<>0 then write(a[i]:4);
close(f1);
close(f2);
readln;
end.
Cho tệp SONGUYEN.INT, chứa dãy số nguyên bất kì. Viết công thức Pascal : Đếm các số chẵn trong dãy số nguyên đó. Kết quả ghi vào tệp TONG.OUT Giúp em với ạ😔
const fi='songuyen.inp'
fo='tong.out'
var f1,f2:text;
a:array[1..100]of integer;
n,i,dem:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
n:=0;
while not eof(f1) do
begin
n:=n+1;
read(f1,a[n]);
end;
dem:=0;
for i:=1 to n do
if a[i] mod 2=0 then inc(dem);
writeln(f2,dem);
close(f1);
close(f2);
end.
Cho tệp ăn.txt chứa dãy các số nguyên liên tiếp viết cách nhau 1 dấu cách .viết CT đọc dữ liệu từ tệp txt tính tổng các số chẵn và tổng các số lẻ ghi kết quả vào tập kq.txt trên 2 dòng
Cho tệp SONGUYEN.TXT chứa cac số nguyên dương N. Viết ct in ra các số chẵn nhỏ hơn hoặc bằng N; Tính tổng các số chẵn đó. Kết quả ghi vào tệp SOCHAN.TXT a) XĐ input, output bài toán b) Viết ct giải quyết bài toán trên Mô tả - Tệp SONGUYEN.TXT chứa các số nguyên dương N - Tệp SOCHAN.TXT dòng ban đầu chứa các số chẵn nhỏ hơn hoặc bằng N - Dòng 2 chứa tổng số chẵn AI GIÚP EM VỚI Ạ Cứuuuuu e
a)
Input: Số nguyên dương N, dãy số a1,a2,a3,...,an
Output: Tổng các số chẵn nhỏ hơn hoặc bằng N
b)
Program HOC24;
var i,n: integer;
t: longint;
a: array[1..1000] of integer;
f1,f2: text;
const fi='SONGUYEN.TXT'
fo='SOCHAN.TXT'
begin
assign(f1,fi);
assign(f2,fo);
reset(f1);
rewrite(f2);
readln(f1,n);
for i:=1 to n do read(f1,a[i]);
for i:=1 to n do if (a[i] mod 2=0) and (a[i]<=n) then
begin
write(f2,a[i],' ');
t:=t+a[i];
end;
writeln(f2);
write(f2,t);
close(f1); close(f2);
end.
Cho tệp bai1.inp gồm:
Hàng 1:Chứa số nguyên N
Hàng 2:Chứa dãy số nguyên gồm N chữ số
Yêu cầu:-Tính tổng các số lẻ và đếm các số chẵn của dãy số trên
-Ghi kết quả tổng và đếm vào tệp bai1.out
const fi='bai1.inp'
fo='bai1.out'
var f1,f2:text;
a:array[1..100]of integer;
n,i,t,dem:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n);
for i:=1 to n do
read(f1,a[i]);
t:=0;
dem:=0;
for i:=1 to n do
begin
if a[i] mod 2<>0 then t:=t+a[i]
else inc(dem);
end;
writeln(f2,'Tong cac so le la: ',t);
writeln(f2,'So so chan la: ',dem);
close(f1);
close(f2);
end.
Cho 1 mảng ( dãy số ) có 10 phàn tử là các số nguyên bất kì . Viết chương trình : a) In ra các phần tử chẵn có trong dãy số b) Tính tổng các phần tử lẻ trong dãy số
giúp mik với mai thi mik thi rồi🙏🙏
program b1;
uses crt;
var i: integer; a:array[1..100] of integer; s:longint;
begin
clrscr;
for i:=1 to 10 do
begin
write('a[',i,']='); readln(a[i]);
end;
writeln('cac phan tu chan la:');
s:=0;
for i:=1 to 10 do if a[i] mod 2=0 then writeln(a[i],' ');
write('Tong cac phan tu le la:');
for i:=1 to 10 do if a[i] mod 2<>0 then s:=s+a[i]; write(s);
readln;
end.
Tham khảo!
Viết ct nhập giá trị cho một dãy số nguyên có n phần tử a. In dãy vừa nhập b. Tính tổng các số trong dãy in kết quả nhận được ra màn hình
#include <bits/stdc++.h>
using namespace std;
long long a[1000],n,i,t;
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++) t+=a[i];
cout<<t;
return 0;
}
Viết chương trình nhập 1 dãy số gồm N số nguyên N≤100 in dãy vừa nhập.Tính và đưa ra màn hình tổng các số chia hết cho 2 nhưng không chia hết cho 3 trong dãy trên.Ghi kết quả vừa tính được vào tệp Bài tập.Out
Giúp mình với ạ