1. Viết chương trình Pascal tính tổng các số chia hết cho 3 từ 1 đến 100 Kết quả tổng này là số chẵn hay lẻ? 2. Viết chương trình Pascal nhập vào 1 mảng số nguyên A gồm có N số (N< 100). Có bao nhiêu số chẵn trong mảng A.
1 Nhập dãy số nguyên gồm n phần tử viết chương trình in ra những số có giá trị lẻ 2 nhập vào dãy số nguyên gồm n phần tử viết chương trình tính tổng các số chẵn có trong mảng 3 nhập vào dãy số nguyên gồm n phần tử viết chương trình tính tổng các số lẻ có trong mảng
Bài 1:
uses crt;
var a:array[1..100]of integer;
i,n:integer;
begin
clrscr;
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
if a[i] mod 2<>0 then write(a[i]:4);
readln;
end.
Bài 2:
uses crt;
var a:array[1..100]of integer;
i,n:integer;
begin
clrscr;
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
if a[i] mod 2=0 then write(a[i]:4);
readln;
end.
Bài 3:
uses crt;
var a:array[1..100]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] mod 2<>0 then t:=t+a[i];
writeln(t);
readln;
end.
1:Viết chương trình Pascal nhập vào mảng a gồm n phần tử nguyên (n<100). Sau đó in ra màn hình mảng vừa nhập, tính giá trị của các phần tử có giá trị là số chẵn, in tổng đó.
2:Viết chương trình Pascal nhập vào mảng a gồm n phần tử nguyên (n<100). Sau đó in ra màn hình mảng vừa nhập, tính giá trị của các phần tử có giá trị là số lẻ, in tổng đó.
giúp mik 2 câu này với ạ
Bài 1
Var a:array:[1..99] of integer;
i,n:integer;
s:longint;
Begin
Repeat
Write('n = ');readln(n);
Until (n > 0) and (n < 100);
For i:=1 to n do
Begin
Write('Nhap diem thu ',i,' = ');readln(a[i]);
if a[i] mod 2 = 0 then s:=s+a[i];
End;
Write('Cac so vua nhap la: ');
For i:=1 to n do
Write(a[i]:8);
writeln;
write('Tong cac so chan la ',s);
Readln
End.
Bài 2
Var a:array:[1..99] of integer;
i,n:integer;
s:longint;
Begin
Repeat
Write('n = ');readln(n);
Until (n > 0) and (n < 100);
For i:=1 to n do
Begin
Write('Nhap diem thu ',i,' = ');readln(a[i]);
if a[i] mod 2 <> 0 then s:=s+a[i];
End;
Write('Cac so vua nhap la: ');
For i:=1 to n do
Write(a[i]:8);
writeln;
write('Tong cac so le la ',s);
Readln
End.
Bài 1. Viết chương trình nhập vào 1 mảng a gồm n phần tử nguyên được nhập từ bàn phím.
a) Tính tổng các số chẵn và lớn hơn 10? Thông báo kết quả và in mảng ra màn hình?
b) Đếm các số lẻ hoặc nhỏ hơn 100? Thông báo kết quả và in mảng ra màn hình?
#include <bits/stdc++.h>
using namespace std;
long long x,n,i,t,dem;
int main()
{
cin>>n;
dem=0;
t=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x%2==0 && x>10) t+=x;
if (x%2!=0 || x<100) dem++;
}
cout<<t<<" "<<dem;
return 0;
}
Viết chương trình - nhập vào mảng 1 chiều gồm n số nguyên n nhỏ hơn hoặc bằng 100 - tính tổng các phần tử trong mảng -tính các tổng chẵn ,lẻ trong mảng
#include <bits/stdc++.h>
using namespace std;
long long x,n,i,t1,t2,t3;
int main()
{
cin>>n;
t1=0; t2=0; t3=0;
for (i=1; i<=n; i++)
{
cin>>x;
t1+=x;
if (x%2==0) t2+=x;
else t3+=x;
}
cout<<t1<<" "<<t2<<" "<<t3;
return 0;
}
Viết chương trình pascal nhập mảng A gồm N số nguyên. Tính và đưa ra màn hình tổng các phần tử của mảng A thỏa điểu kiện cho trước (chẵn, lẻ, âm , dương,…)
(Viết chương trình Pascal sử dụng câu lệnh while...do)
1. Viết chương trình nhập vào 1 dãy gồm n số nguyên và tính tổng, trung bình của dãy vừa nhập.
2. Viết chương trình nhập 1 số nguyên x, kiểm tra số vừa nhập có phải số nguyên tố hay không.
Bài 1
Var s,i:integer;
tb:real;
Begin
Write('Nhap n = ');readln(n);
i:=1;
s:=0;
While i<=n do
Begin
s:=s+i;
i:=i+1;
End;
tb:=s/n;
Writeln('Tong la ',s);
Write('Trung binh la ',tb:10:2);
Readln;
End.
Bài 2
Var i,n,souoc:integer;
Begin
Write('Nhap n = ');readln(n);
i:=1;
While i <= n do
Begin
i:=i + 1;
If n mod i = 0 then souoc:=souoc + 1;
End;
If souoc = 1 then write(n,' la so nguyen to')
Else write(n,' khong la so nguyen to');
Readln;
End.
Bài 1: Viết chương trình pascal thực hiện các yêu cầu sau: a) Nhập từ bàn phím 1 số nguyên n b) In ra màn hình kết quả tổng các số nguyên từ 1 đến n (sử dụng câu lệnh lặp while...do) Bài 2: Viết chương trình pascal thực hiện câc yêu cầu sau: a) Nhập từ bàn phím 1 số nguyên dương n b) In ra màn hình kết quả tổng các số lẻ từ 1 đến n (sử dụng câu lệnh lặp while...do giúp mình với mình đang cần gấp rất gấp luôn
Bài 1:
uses crt;
var n,i,s:integer;
begin
clrscr;
write('Nhap n='); readln(n);
s:=0;
i:=1;
while i<=n do
begin
s:=s+i;
inc(i);
end;
writeln('Tong cac so trong khoang tu 1 den ',n,' la: ',s);
readln;
end.
Bài 2:
uses crt;
var n,i,s:integer;
begin
clrscr;
write('Nhap n='); readln(n);
s:=0;
i:=1;
while i<=n do
begin
s:=s+i;
i:=i+2;
end;
writeln('Tong cac so le trong khoang tu 1 den ',n,' la: ',s);
readln;
end.
Cho mảng A có n phần tử dùng chương trả con thực hiện một số yêu cầu như sau: 1. Viết chương trình nhập mảng A 2. Tính tổng số chẵn, lẻ 3. Tính có bao nhiêu phần tử chia hết cho k.
a)
uses crt;
var i,n:integer;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until n<100;
if n mod 2=0 then
begin
for i:=0 to n do
if i mod 2=0 then write(i:4);
end
else writeln(n,' khong la so chan');
readln;
end.
b)
uses crt;
var i,n:integer;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until n<100;
if n mod 2=1 then
begin
for i:=1 to n do
if i mod 2=1 then write(i:4);
end
else writeln(n,' khong la so le');
readln;
end.