Viết chương trình nhập vào mảng một chiều C gồm có n số nguyên. Ghi mảng C vừa nhập vào tệp có tên là MANG3.TXT. Đọc dữ liệu từ tệp MANG3.TXT, in ra màn hình các số lẻ trong mảng.
Viết chương trình nhập vào mảng một chiều C gồm có n số nguyên. Ghi mảng C vừa nhập vào tệp có tên là MANG3.TXT. Đọc dữ liệu từ tệp MANG3.TXT, in ra màn hình các số lẻ trong mảng.
Program HOC24;
var i,n: integer;
c: array[1..1000] of integer;
f: text;
begin
assign(f,'MANG3.TXT');
reset(f);
readln(f,n);
for i:=1 to n do read(f,c[i]);
close(f);
for i:=1 to n do if c[i] mod 2=1 then write(c[i],' ');
readln
end.
Câu 1: Viết chương trình nhập n phần tử mảng 1 chiều là các số nguyên từ bàn phím, ghi mảng vừa nhập vào tệp MANG1CHIEU.TXT. Tìm giá trị nhỏ nhất trong mảng và đưa kết quả ra màn hình
Câu 2: Viết chương trình nhập 1 xâu bất kỳ từ bàn phím, In ra xâu sau khi đã loại bỏ các kí tự là chữ cái và ghi vào tệp CHUSO.TXT
giúp em với ạ . em cảm ơn nhiều...
cau 1:
uses crt;
var a:array[1..100] of integer;
n,i,min: integer;
begin
readln(n);
for i:=1 to n do
readln(a[i]);
min:=a[1];
for i:=2 to n do
if min>a[i] then min=a[i];
writeln(a[i]);
readln;
end.
cau 2:
uses crt;
g:text;
s:string;
const fo='CHUSO.TXT'
begin
assign(g,fo);
rewrite(g);
readln(s);
for i:=1 to length(s) do
if not((s[i] in ['a'..'z'])and(s[i] in ['A'..'Z])) then delete(s,i,1);
writeln(g,s);
end.
BT1: Viết chương trình nhập vào một mảng gồm 10 phần tử số nguyên. In ra màn hình mảng vừa nhập và tính tổng các phần tử trong mảng. BT2: Viết chương trình nhập vào một mảng gồm 10 phần tử số thực. In ra màn hình các phần tử có chỉ số chẵn trong mảng. BT3: Viết chương trình nhập vào một mảng gồm n phần tử số nguyên. In ra màn hình các phần tử có giá trị chẵn trong mảng. BT4: Viết chương trình nhập vào một mảng gồm n phần tử số nguyên. In ra màn hình phần tử có giá trị lớn nhất trong mảng. BT5: Viết chương trình nhập vào một mảng gồm n phần tử số thực. In ra màn hình chỉ số của phần tử nhỏ nhất trong mảng. BT6: Viết chương trình nhập vào một mảng gồm n phần tử số nguyên. Đếm xem trong mảng vừa nhập có bao nhiêu phần tử lẻ.
6:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,A[100],i,dem=0;
cin>>n;
for (int i=1; i<=n; i++) cin>>A[i];
for (int i=1;i<=n; i++)
if (A[i]%2!=0) dem++;
cout<<dem;
return 0;
}
5:
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n,nn=1e6,A[1000];
cin>>n;
for (int i=1; i<=n; i++) cin>>A[i];
for (int i=1; i<=n; i++)
nn=min(nn,A[i]);
for (int i=1; i<=n; i++)
if (nn==A[i]) cout<<i<<" ";
return 0;
}
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.
Viết chương trình nhập vào một mảng gồm n số nguyên a.in ra mảng vừa nhập b.tính và in ra màn hình tổng các cân bậc hai của các số nguyên dương trong mảng vừa nhập
#include <bits/stdc++.h>
using namespace std;
long long a[1000],i,n,t,dem;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
for (i=1; i<=n; i++) cout<<a[i]<<" ";
cout<<endl;
dem=0;
t=0;
for (i=1; i<=n; i++)
if (a[i]>0)
{
dem++;
t=t+sqrt(a[i]);
}
cout<<t;
return 0;
}
Cho tệp văn bản có tên DATA2.TXT chứa một xâu bất kì không quá 255 kí tự gồm các chữ và số. Viết chương trình đọc xâu kí tự S từ từ tệp DATA2.TXT sau đó ghi dữ liệu là các thông tin sau vào tệp KQ2.TXT:
- Dòng 1: Số lần xuất hiện của kí tự "k" trong xâu?
- Dòng 2: Số lượng kí tự là số xuất hiện trong S (giữ nguyên thứ tự xuất hiện)?
Cho tệp văn bản có tên DATA2.TXT chứa một xâu bất kì không quá 255 kí tự gồm các chữ và số. Viết chương trình đọc xâu kí tự S từ từ tệp DATA2.TXT sau đó ghi dữ liệu là các thông tin sau vào tệp KQ2.TXT:
- Dòng 1: Số lần xuất hiện của kí tự "k" trong xâu?
- Dòng 2: Số lượng kí tự là số xuất hiện trong S (giữ nguyên thứ tự xuất hiện)?
Cho tệp văn bản có tên DATA2.TXT chứa một xâu bất kì không quá 255 kí tự gồm các chữ và số. Viết chương trình đọc xâu kí tự S từ từ tệp DATA2.TXT sau đó ghi dữ liệu là các thông tin sau vào tệp KQ2.TXT:
- Dòng 1: Số lần xuất hiện của kí tự "k" trong xâu?
- Dòng 2: Số lượng kí tự là số xuất hiện trong S (giữ nguyên thứ tự xuất hiện)?
Help me!!! Mai mk thi ạ
Cho tệp văn bản có tên DATA2.TXT chứa một xâu bất kì không quá 255 kí tự gồm các chữ và số. Viết chương trình đọc xâu kí tự S từ từ tệp DATA2.TXT sau đó ghi dữ liệu là các thông tin sau vào tệp KQ2.TXT:
- Dòng 1: Số lần xuất hiện của kí tự "k" trong xâu?
- Dòng 2: Số lượng kí tự là số xuất hiện trong S (giữ nguyên thứ tự xuất hiện)?