Viết chương trình nhập vào bàn phím mảng 1 chiều gồm n phần tử. Đếm số phần tử đặc biệt trong mảng: Các phần tử dương ( âm, ko dương, ko âm) đồng thời chia hết(ko chia hết) cho 1 số bất kỳ.
Mn giúp em vs ạ!!!
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.
Bài 1: Hãy viết chương trình con thực hiện các công việc sau trên mảng một chiều:
+ Nhập vào 1 mảng
+ In mảng + Sắp xếp mảng tăng dần
+ Tính tổng các phần tử trong mảng
+ Đếm các phần tử chia hết cho 3 trong mảng
+ Đếm các số âm, dương trong mảng
Bài 2: Viết chương trình con để tính diện tích các hình sau:
- Diện tích hình tam giác theo công thức herrong khi biết độ dài 3 cạnh a, b, c của tam giác. S=sqrt(p*(p-a)*(p-b)*(p-c)) với p=(a+b+c)/2
- Diện tích hình thang khi biết độ dài chiều cao h và 2 cạnh đáy a, b S=(a+b)*h/2 - Diện tích hình vuông khi biết độ dài cạnh.
Bài 3: Viết chương trình giải phương trình bậc 2 sử dụng chương trình con
viết chương trình nhập vào mảng một chiều.gồm phần tử số nguyên N được nhập từ bàn phím. N nguyên, dương, N<=10
A, in mảng vừa nhập ra màn hình
B, tính tổng các phần tử có giá trị chẵn, in kết qua ra màn hình
C, đếm số lượng các phần tử chia hết cho 3
D, tính trung bình cộng các số có giá trị lẻ
E, in ra màn hình các phần tử là số nguyên tố
mong được giúp đỡ
#include <bits/stdc++.h>
using namespace std;
long long a[100],n,i,t,t1,dem,dem1;
//chuongtrinhcon
bool ktnt(long long x)
{
if (x<=1) return(false);
for (int i=2; i*i<=x; i++)
if (x%i==0) return(false);
return true;
}
//chuongtrinhchinh
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=t+a[i];
cout<<t<<endl;
dem=0;
for (i=1; i<=n; i++) if (a[i]%3==0) dem++;
cout<<dem<<" ";
t1=0;
dem1=0;
for (i=1; i<=n; i++)
if (a[i]%2!=0)
{
t1+=a[i];
dem1++;
}
cout<<fixed<<setprecision(2)<<(t1*1.0)/(dem1*1.0)<<endl;
for (i=1; i<=n; i++)
if (ktnt(a[i])==true) cout<<a[i]<<" ";
return 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!!
viết chương trình nhập vào 1 mảng 1 chiều gồm n phần tử ( với n được nhập vào từ bàn phím ) hãy thực hiện các công việc sau :
-nhập/xuất mảng
-đếm các số hoàn hảo có trong mảng
-tính tổng các phần tử chẵn trong mảng .
#include <bits/stdc++.h>
using namespace std;
long long a[1000],n,i,dem,t,j,t1;
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;
for (i=1; i<=n; i++)
{
t=0;
for (j=1; j<=a[i]-1; j++)
if (a[i]%j==0) t+=j;
if (t==a[i]) dem++;
}
cout<<dem<<endl;
t1=0;
for (i=1; i<=n; i++)
if (a[i]%2==0) t1+=a[i];
cout<<t1;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
long long a[1000],n,i,dem,t,j,t1;
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;
for (i=1; i<=n; i++)
{
t=0;
for (j=1; j<=a[i]-1; j++)
if (a[i]%j==0) t+=j;
if (t==a[i]) dem++;
}
cout<<dem<<endl;
t1=0;
for (i=1; i<=n; i++)
if (a[i]%2==0) t1+=a[i];
cout<<t1;
return 0;
}
viết chương trình nhập vào 1 mảng 1 chiều gồm n phần tử ( với n được nhập vào từ bàn phím ) hãy thực hiện các công việc sau :
-nhập/xuất mảng
-đếm các số hoàn hảo có trong mảng
-tính tổng các phần tử chẵn trong mảng .
#include <bits/stdc++.h>
using namespace std;
long long a[1000],n,i,dem,t,j,t1;
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;
for (i=1; i<=n; i++)
{
t=0;
for (j=1; j<=a[i]-1; j++)
if (a[i]%j==0) t+=j;
if (t==a[i]) dem++;
}
cout<<dem<<endl;
t1=0;
for (i=1; i<=n; i++)
if (a[i]%2==0) t1+=a[i];
cout<<t1;
return 0;
}
Viết chương trình nhập vào 1 mảng 1 chiều gồm n phần tử (với n được nhập vào từ bàn phím). Hãy thực hiện các công việc sau:
- Nhập các phần tử mảng từ bàn phím.
- Hiển thị mảng vừa nhập ra màn hình.
- In ra màn hình các số chính phương trong mảng.
- Đếm trong mảng có bao nhiêu phần tử có giá trị bằng 5. Nếu không có phần tử nào có giá trị bằng 5 thì in ra màn hình thông báo “Không có phần tử nào thỏa mãn điều kiện”
#include <bits/stdc++.h>
using namespace std;
long long n,i,a[10000];
int main()
{
cin>>n;
for (i=1; i<=n; i++)
cin>>a[i];
for (i=1; i<=n; i++) cout<<a[i]<<" ";
return 0;
}
uses crt;
var a:array[1..100]of integer;
i,n,dem:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']=');readln(a[i]);
end;
dem:=0;
for i:=1 to n do
if (a[i] mod 3=0) and (a[i] mod 5=0) then inc(dem);
writeln('So phan tu chia het cho 3 va 5 trong day la: ',dem);
readln;
end.
Viết chương trình:
- Nhập mảng gồm n phần tử, với n được nhập vào từ bàn phím
- In mảng lên màn hình
- In ra màn hình số phần tử chia hết cho 2
- Tính và in ra màn hình tổng các phần tử của mảng
#include <bits/stdc++.h>
using namespace std;
long long a[10000],n,i,t;
int main()
{
cin>>n;
t=0;
for (i=1; i<=n; i++)
{
cin>>a[i];
t=t+a[i];
}
for (i=1; i<=n; i++) cout<<a[i]<<" ";
cout<<endl;
dem=0;
for (i=1; i<=n; i++)
if (a[i] %2==0) dem++;
cout<<dem<<endl;
cout<<t;
return 0;
}