Dùng câu lệnh while...do viết chương trình nhập các số nguyên kết thúc khi nhập bằng 0. Tính tổng các số chẵn, tổng các só lẻ đã nhập, rồi in kết quả ra màn hình?
Dùng câu lệnh while...do viết chương trình nhập các số nguyên kết thúc khi nhập bằng 0 . Tính tổng các số chẵn , tổng câc số lẻ đã nhập rồi in kết quả ra màn hình
uses crt;
var n,i,t1,t2:integer;
begin
clrscr;
t1:=0;
t2:=0;
repeat
readln(n);
if n mod 2=0 then t1:=t1+n
else t2:=t2+n;
until n=0;
writeln(t1,' ',t2);
readln;
end.
Viết chương trình nhập vào 1 dãy số nguyên gồm n phần tử (với n được nhập từ bàn phím, n<=15) Tính tổng các số của dãy và in kết quả tổng tính đc ra màn hình(dùng câu lệnh lặp while..do)
Var a:array[1..15] of integer;
i,s:integer;
Begin
I:=1;
While i<=15 do
Begin
Write('Nhap phan tu thu ',i,' = ');readln(a[i]);
s:=s+a[i];
i:=i+1;
End;
Write('Tong la ',s);
Readln;
End.
Viết chương trình nhập vào một dãy số, chương trình chỉ dừng lại khi số nhập vào là số 0. In ra màn hình các kết quả sau: - In ra tổng của các số chẵn đã nhập vào? - In ra tích của các số lẻ đã nhập vào?
Giúp tui với mn ơi
uses crt;
var n,t1:integer;
s:real;
begin
clrscr;
t1:=0;
s:=1;
repeat
readln\(\left(n\right)\);
if n mod 2=0 then t1:=t1+n
else s:=s*n;
until n=0;
writeln\(\left(t1\right)\);
writeln\(\left(s:4:2\right)\);
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.
Viết chương trình nhập vào nhiều số nguyên từ bàn phím, việc nhập kết thúc khi ta nhập vào số 0 hoặc nhập đủ 10 số. a) Đếm và in ra số các số đã nhập, không tính số 0. (VD: nhập 7, 4, 9, 0 -> Đã nhập 3 số) b)Tính và in ra tổng các số lẻ đã nhập
2.Viết chương trình nhập vào điểm theo thang điểm 10. Đổi sang thang điểm 4 và in kết quả ra màn hình. Biết từ 8.5 đến 10 thì đổi sang thang điểm 4 là 4. Từ 7 đến dưới 8.5 thì đổi sang thang điểm 4 là 3. Từ 5.5 đến dưới 7 thì đổi sang thang điểm 4 là 2. Từ 4 đến dưới 5.5 thì đổi sang thang điểm 4 là 1. Còn dưới 4 thì đổi sang thang điểm 4 là 0
mọi người code giùm ạ em cám ơn ngôn ngữ c
Bài 1:
#include <bits/stdc++.h>
using namespace std;
long long a[10],n,i,t;
int main()
{
n=0;
do
{
cin>>a[i];
}
while ((a[i]==0) or (n==10));
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;
return 0;
}
Viết chương trình nhập vào từ bàn phím một số nguyên dương n, in ra màn hình các số lẻ nhỏ hơn hoặc bằng số nguyên dương n. Chương trình yêu cầu nhập lại nếu n <=0. (Sử dụng câu lệnh While … do)
program Le_Nho_Hon_Hoac_Bang_n;
uses crt;
var
n, i: integer;
begin
clrscr;
write('Nhap vao mot so nguyen duong n: ');
readln(n);
while n <= 0 do
begin
writeln('So ban nhap khong hop le. Xin vui long nhap lai: ');
readln(n);
end;
clrscr;
writeln('Cac so le nho hon hoac bang ', n, ' la:');
i := 1;
while i <= n do
begin
if i mod 2 <> 0 then
writeln(i);
i := i + 1;
end;
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 số nguyên dương n . Tính và in ra màn hình các kết quả sau bằng ngôn ngữ Python : - Số lượng số lẻ từ 0 --> n - Số lượng số nguyên tố từ 0 --> n - Tổng của những số chẵn từ 0 --> n In ra tất cả các số là số chính phương trong phạm vi từ 0 --> n ( nếu có )
Câu 1: Viết chương trình nhập 10 số nguyên N và tính tổng các số đó
Câu 2: Viết chương trình nhập 10 số nguyên N và in ra màn hình số lượng các số chẳn đã nhập được
Câu 3: Viết chương trình nhập 2 số M, N (M nhỏ hơn N) in ra màn hình các số lẻ có trong khoảng từ M đến N
Các bạn ai đó giúp mình làm những bài này nhé. Cảm ơn!
1:
uses crt;
var t,x,i,n:integer;
begin
clrscr;
t:=0;
n:=10;
for i:=1 to n do
begin
readln(x);
t:=t+x;
end;
write(t);
readln;
end.
2:
uses crt;
var dem,x,i,n:integer;
begin
clrscr;
dem:=0;
n:=10;
for i:=1 to n do
begin
readln(x);
if x mod 2=0 then inc(dem);
end;
write(dem);
readln;
end.
3
program Cacsole;
uses crt;
var M, N, i: integer;
begin
clrscr;
write ('Nhap M= '); readln(M);
write ('Nhap N= '); readln(N);
for i := M to N do
if i mod 2 = 1 then
write (i,' ');
readln;
end.