Viết chương trình nhập từ bàn phím 10 số nguyên ,hãy ghi 10 số nguyên đó vào tệp KQ.Txt . Hai dòng ,5 số trên 1 dòng , mỗi sôa cách nhau 1 dấu cách
viết chương trình nhập từ bàn phím 15 số thực ghi các số đó vào tệp KQ.TXT cứ 5 số trên một dòng các số cách nhau bởi một dấu cách?
uses crt;
const fi='kq.txt'
var a:array[1..15]of real;
i,n:integer;
f1:text;
begin
clrscr;
n:=15;
for i:=1 to n do readln(a[i]);
assign(f1,fi); rewrite(f1);
for i:=1 to n do
begin
if (i mod 5=0) then writeln(f1)
else write(f1,a[i],' ');
end;
close(f1);
readln;
end.
Viết công thức nhập vào từ bàn phím 10 số nguyên bất kì . Ghi 10 số nguyên trên vào tệp KQ.TXT và 10 số nguyên trên nằm trên 1 hàng và mỗi số cách nhau 1 dấu cách (hàng 1).và ghi số lượng số dương vào hàng 2 trong tệp ?
uses crt;
const fi='kq.txt'
var a:array[1..10]of integer;
i,n,dem:integer;
f1:text;
begin
clrscr;
n:=10;
for i:=1 to n do readln(a[i]);
assign(f1,fi); rewrite(f1);
for i:=1 to n do write(f1,a[i]:4);
writeln(f1);
dem:=0;
for i:=1 to n do if a[i]>0 then dem:=dem+1;
writeln(f1,dem);
close(f1);
readln;
end.
Viết công thức nhập vào từ bàn phím 10 số nguyên bất kì . Ghi 10 số nguyên trên vào tệp KQ.TXT và 10 số nguyên trên nằm trên 1 hàng và mỗi số cách nhau 1 dấu cách (hàng 1).và ghi số lượng số dương vào hàng 2 trong tệp ?
Cho tệp DL.TXT có nội dung như sau: - Số nguyên n ( dòng 1 ) - Dãy gồm n số nguyên ( dòng 2 ) ( Các số cách nhau bởi dấu cách ) Viết chương trình ghi các số chẵn của dãy số trên vào tệp KQ.TXT
Cho mảng 1 chiều a thừa số nguyên gồm 10 phần tử đc nhập từ bàn phím viết phương trình ghi tệp 1 để ghi các phần tử của mảng a vào tệp trong Data. TXT các phần tử đc ghi trên 1 dòng mỗi phần tử cách nhau ít nhất 1 khoảng trống
uses crt;
const fo='data.txt'
var f1:text;
a:array[1..10]of integer;
i,n:integer;
begin
clrscr;
assign(f1,fo); rewrite(f1);
n:=10;
for i:=1 to n do readln(a[i]);
for i:=1 to n do write(f1,a[i]:4);
close(f1);
readln;
end.
1. Viết chương trình tạo tệp baitap.txt trong đó dòng đầu tiên n là số lượng các số nguyên, dòng thứ 2 là n số nguyên cách nhau 2 kí tự trắng được nhập từ bàn phím (N<=100)
2.Viết chương trình tìm số nguyên lớn nhất trong n số nguyên đã có trong tệp baitap.txt và ghi kết quả vào tệp solonnhat.txt
Mong mọi người giúp mình giải sớm =(((
Câu 2:
uses crt;
var a,b:integer;
{-----------------chuong-trinh-con-------------------}
function ucln(x,y:integer):integer;
var i,uc:integer;
begin
if x<y then
begin
uc:=1;
for i:=1 to x do
if (x mod i=0) and (y mod i=0) then
begin
if uc<i then uc:=i;
end;
end
else begin
uc:=1;
for i:=1 to y do
if (x mod i=0) and (y mod i=0) then
begin
if uc<i then uc:=i;
end;
end;
ucln:=uc;
end;
{--------------------------chuong-trinh-chinh------------------------}
begin
clrscr;
write('Nhap a='); readln(a);
write('Nhap b='); readln(b);
writeln(a,'/',b,'=',a div ucln(a,b),'/',b div ucln(a,b));
readln;
end.
Câu 1:
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.
viết chương trình tạo tệp baitap.txt trong dó dòng đầu tiên là n số lượng các số nguyên, dòng thứ hai là n số nguyên cách nhau 2 kí tự trắng được nhập từ bàn phím
uses crt;
const fi='baitap.txt'
var f1:text;
a:array[1..100]of integer;
n,i:integer;
begin
clrscr;
assign(f1,fi); rewrite(f1);
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
writeln(f1,n);
for i:=1 to n do
write(f1,a[i]:4);
close(f1);
readln;
end.
viết chương trình nhập n từ bàn phím(n<=200) và dãy số a1,a2..an từ bàn phím, ghi vào tệp B.TXT mỗi số trên 1 dòng
uses crt;
const fo='b.txt'
var f1:text;
a:array[1..200]of integer;
i,n:integer;
begin
clrscr;
assign(f1,fo); rewrite(f2);
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
write(f1,a[i]:4);
close(f1);
readln;
end.
program cap_so_cong;
uses crt; var a: array[1..100] of integer; i, n, k: integer;
{i la bien dem, k de luu cap so} begin clrscr; write('N= ');
readln(n); for i:=1 to n do begin write('A(',i,')= ');
readln(a[i]);
end;
{Bat dau phan kiem tra} k:=a[2]-a[1]; i:=2; repeat i:= i+1; until (a[i]<>a[i-1]+k) or (i>n);
if i>n then write('Day A la mot cap so cong') else
write('Day A khong phai la mot cap so cong');
readln
end.
Nhập vào từ bàn phím số nguyên dương N (1<N 10')
- Dòng 1: Tổng các chữ số của N.
- Dòng 2: Số lượng các số nguyên dương, không phải là số nguyên tố nhỏ hơn N
- Dòng 3: Ghi hai số 7 và K cách nhau 1 dấu cách : I10 cho tổng thu K số nguyên liên tiếp bắt đầu từ Z bằng N, trường hợp tồn tại nhiều giá trị Z, thì hiển thị màn hình kết quả có giá trị Z nhỏ nhất
- Dòng 4: Ghi số X là số lượng các chữ số cần dùng để chỉnh chốt quyển sách có N
Ví dụ :nhập vào 15
in ra d1:6
d2:8
d3:1 5
d4:21
#include <bits/stdc++.h>
using namespace std;
long long n,i,x,t,dem,j;
int main()
{
cin>>n;
x=n;
t=0;
while (n>0)
{
t=t+n%10;
n=n/10;
}
cout<<t;
dem=0;
for (i=2; i<=x; i++)
{
bool kt=true;
for (j=2; j*j<=i; j++)
if (i%j==0) kt=false;
if (kt==true) dem++;
}
cout<<dem;
return 0;
}