các cậu giúp mình câu viết chương trình này với nha,bài này khó viết quá nên mong các bạn giúp mình !!!
đề: viết chương trình thực hiện nhập vào 10 phần tử có giá trị nguyên cho mảng A từ bàn phím và tính tổng các phần tử lẻ có trong mảng A.
Viết chương trình thực hiện công việc nhập N (N<=50) phần tử có giá trị nguyên cho mảng A từ bàn phím. In ra màn hình tổng các phần tử trong mảng Anhờ các hảo hán tin học giải giúp sư đệ
1.viết chương trình nhập vào mảng A gồm N phần tử (N<= 500) từ bàn phím. Sau đó, tính tổng các phần tử âm chia hết cho cho 7
2.viết chương trình nhập vào mảng C gồm 10 phần tử từ bàn phím. Sau đó xuất ra các phần tử là số nguyên tố
3.viết chương trình tạo nhập vào mảng D gồm K phần tử (K<= 200) từ bàn phím. Sau đó cho biết có bao nhiêu phần tử chẵn có 2 chữ số
mn giúp em giải với ạ
Câu 1:
uses crt;
var a:array[1..500]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]<0) and (a[i] mod 7=0) then t:=t+a[i];
writeln('Tong cac so am chia het cho 7 la: ',t);
readln;
end.
Câu 2:
uses crt;
var c,a:array[1..10]of integer;
i,kt,j,dem:integer;
begin
clrscr;
for i:=1 to 10 do
begin
write('C[',i,']='); readln(c[i]);
end;
dem:=0;
for i:=1 to 10 do
if c[i]>1 then
begin
kt:=0;
for j:=2 to c[i]-1 do
if c[i] mod j=0 then kt:=1;
if kt=0 then
begin
inc(dem);
a[dem]:=c[i];
end;
end;
if dem=0 then writeln('Trong day khong co so nguyen to')
else begin
writeln('Cac so nguyen to trong day la: ');
for i:=1 to dem do
write(a[i]:4);
end;
readln;
end.
Câu 3:
uses crt;
var d:array[1..200]of integer;
i,k,dem:integer;
begin
clrscr;
write('Nhap k='); readln(k);
for i:=1 to k do
begin
write('D[',i,']='); readln(d[i]);
end;
dem:=0;
for i:=1 to k do
if (a[i] mod 2=0) and (a[i]>=10) then inc(dem);
writeln('So phan tu chan co 2 chu so la: ',dem);
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.
5. Viết chương trình a. Viết chương trình nhập và in ra 1 mảng gôm 40 phần tử kiểu số nguyên b. Viết chương trình nhập vào 1 mảng n số thực và in ra mảng đó ( với n là sô nguyên được nhập từ bàn phím và 0
Cho 1 mảng a gồm 100 phần tử em hãy viết chương trình đếm số lượng các phần tử chia hết cho giá trị x nhập vào tử bàn phím, in ra màn hình các phần tử đó Mình đang cần gấp mọi người giúp mình với ạ🤦
#include <bits/stdc++.h>
using namespace std;
int n,x,i,cnt,res;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>cnt;
for(i=0;i<n;i++)
{
cin>>x;
if(x%cnt==0) res++;
}
cout<<"so luong phan tu chia het cho "<<cnt<<" la: "<<res;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int gh=1000;
int n,x,i,cnt,res,dem[gh];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>cnt;
for(i=0;i<n;i++)
{
cin>>x;
if(x%cnt==0) { res++; dem[res]=x;}
}
cout<<"so luong phan tu chia het cho "<<cnt<<" la: "<<res;
cout<<"\n"<<"cac phan tu do la: "<<"\n";
for(i=1;i<=res;i++)
cout<<dem[i]<<" ";
return 0;
}
// đây mới đúng mik đọc lỗi đề nha bạn!!
Câu 2 Viết chương trình nhập một mảng số nguyên A có độ dài 50 phần tử với số lượng phần tử được nhập từ bàn phím. Thực hiện in ra màn hình các số lẻ có trong mảng.
Var a:array:[1..50] of integer;
i:integer;
s:longint;
Begin
For i:=1 to 50 do
Begin
Write('Nhap so thu ',i,' = ');readln(a[i]);
If a[i] mod 2 <> 0 then
s:=s+a[i];
End;
Write('Tong cac so le la: ',s);
Readln
End.
CHO MÌNH HỎI CÂU TIN NÀY VS
Viết chương trình khai báo mảng 1 chiều tối đa 10 phần tử số nguyên hãy:
a, Thông báo ra màn hình các phần tử>=k(k nhập từ bàn phím)
b,tính tổng các phần tử có giá trị >=k
c, tính tổng tbc các phần tử >=k
viết chương trình thực hiện công việc nhập N (N<=50) phần tử có giá trị nguyên cho mảng A từ bàn phím. In ra màn hình tổng các giá trij là số lẻ có trong mảng Ahelpppppppp, ai giải được cho 400 chịu
program TongLe;
var
N, i, Tong: integer;
A: array[1..50] of integer;
begin
write('Nhap so phan tu cua mang N (N <= 50): ');
readln(N);
for i := 1 to N do
begin
write('Nhap phan tu thu ', i, ': ');
readln(A[i]);
end;
Tong := 0;
for i := 1 to N do
begin
if(A[i] mod 2 <> 0) then
begin
Tong := Tong + A[i];
end;
end;
writeln('Tong cac so le trong mang A la: ', Tong);
readln;
end.
Cho mảng A có N phần tử (N được nhập vào từ bàn phím, các phần tử của mảng là các số nguyên). Hãy viết chương trình Pascal thực hiện các yêu cầu sau: a. Nhập các phần tử cho mảng A? b. In lên màn hình các phần tử của mảng A? c. Tính tổng các phần tử chẵn của mảng A và thông báo kết quả ra màn hình?
program Tinh_Tong_Phan_Tu_Chan;
var
A: array of Integer;
N, i, sum: Integer;
begin
Write('Nhap N: ');
Readln(N);
SetLength(A, N);
// Nhập các phần tử cho mảng A
for i := 0 to N - 1 do
begin
Write('Nhap phan tu thu ', i + 1, ': ');
Readln(A[i]);
end;
// In lên màn hình các phần tử của mảng A
Write('Cac phan tu cua mang la: ');
for i := 0 to N - 1 do
begin
Write(A[i], ' ');
end;
Writeln;
// Tính tổng các phần tử chẵn của mảng A và thông báo kết quả ra màn hình
sum := 0;
for i := 0 to N - 1 do
begin
if A[i] mod 2 = 0 then
sum := sum + A[i];
end;
Writeln('Tong cac phan tu chan cua mang la: ', sum);
Readln;
end.
Viết chương trình nhập vào mảng A gồm N phần tử (N<= 500) từ bàn phím giá trị các phần tử là các số nguyên đưa ra màn hình mảng vừa nhập với thứ tự các phần tử ngược lại, nhập 3, 6, 8 đưa ra 8, 6, 3. Đếm số phần tử có giá trị lớn hơn 10. Đưa ra màn hình số lượng số nguyên tố trong mảng
#include <bits/stdc++.h>
using namespace std;
int A[500],n,i,dem,dem1;
int main()
{
cin>>n;
for (int i=1; i<=n; i++) cin>>A[i];
for (int i=n; i>=1; i--) cout<<A[i]<<" ";
cout<<endl;
dem=0;
for (int i=1; i<=n; i++)
if (A[i]<10) dem++;
cout<<dem<<endl;
dem1=0;
for (int i=1; i<=n; i++)
if (A[i]>1)
{
bool kt=true;
for (int j=2; j*j<=A[i]; j++)
if (A[i]%j==0) kt=false;
if (kt==true) dem1++;
}
cout<<dem1;
return 0;
}