Viết chương trình nhập vào một số nguyên dương có hai chữ số. Hãy dùng các phép toán DIV và MOD để tính tổng hai chữ số của số đó và đưa kết quả ra màn hình? (VD: Nhập số: 25 → đưa ra màn hình: 7)
viết chương trình nhập từ bàn phím số nguyên dương n và dãy số nguyên a1 a2 đến an đưa dãy vừa nhập ra màn hình tính tổng các số chia hết cho 7 đưa kết quả ra màn hình
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;
for i:=1 to n do
write(a[i]:4);
writeln;
t:=0;
for i:=1 to n do
if a[i] mod 7=0 then t:=t+a[i];
writeln('Tong cac so chia het cho 7 la: ',t);
readln;
end.
BT: Viết chương trình nhập vào một dãy N số nguyên dương (N<=150), nhập vào số nguyên dương K.
1. Tìm và đưa ra màn hình số lớn nhất (Max) của dãy vừa nhập, nếu dãy có nhiều số đạt Max thì tính tổng Max và đưa ra màn hình tất cả các vị trí đạt Max.
2. Tìm và đưa ra màn hình số nhỏ nhất (Min) của dãy vừa nhập, nếu dãy có nhiều số đạt Min thì tính tổng Min và đưa ra màn hình tất cả các vị trí đạt Min
3. Đếm và tính tổng các số ở vị trí chẵn là bội của số K trong dãy vừa nhập và đưa kết quả ra màn hình.
4. Đếm và tính tổng các số ở vị trí lẻ là ước của số K trong dãy vừa nhập và đưa kết quả ra màn hình.
5. Số a và số b là anh em của nhau nếu a = b + 1 hoặc b = a + 1. Đếm và tính tổng các số là anh em của K trong dãy vừa nhập và đưa kết quả ra màn hình.
uses crt;
var a,vtmax,vtmin:array[1..100]of integer;
n,i,max,min,dem,t,dem1,t1,dem2,t2,dem3,t3,dem4,t4,k:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
max:=a[1];
for i:=1 to n do
if max<a[i] then max:=a[i];
writeln('So lon nhat trong day la: ',max);
dem:=0;
t:=0;
for i:=1 to n do
if max=a[i] then
begin
inc(dem);
t:=t+a[i];
vtmax[dem]:=i;
end;
if dem>1 then
begin
writeln('Tong cac so max la: ',t);
writeln('Cac vi tri co so max la: ');
for i:=1 to dem do
write(vtmax[i]:4);
end;
min:=a[1];
for i:=1 to n do
if min>a[i] then min:=a[i];
writeln('So nho nhat trong day la: ',min);
dem1:=0;
t1:=0;
for i:=1 to n do
if min=a[i] then
begin
inc(dem1);
t1:=t1+a[i];
vtmin[dem1]:=i;
end;
if dem1>1 then
begin
writeln('Tong cac so min la: ',t1);
writeln('Cac vi tri co so min la: ');
for i:=1 to dem1 do
write(vtmin[i]:4);
end;
write('Nhap k='); readln(k);
dem2:=0;
t2:=0;
for i:=1 to n do
if (i mod 2=0) and (a[i] mod k=0) then
begin
dem2:=dem2+1;
t2:=t2+a[i];
end;
writeln('So phan tu o vi tri chan trong day la boi cua ',k,' la: ',dem2);
writeln('Tong cac so o vi tri chan trong day la boi cua ',k,' la: ',t2);
dem3:=0;
t3:=0;
for i:=1 to n do
if (i mod 2=1) and (k mod a[i]=0) then
begin
inc(dem3);
t3:=t3+a[i];
end;
writeln('So phan tu o vi tri le trong day la uoc cua ',k,' la: ',dem3);
writeln('Tong cac so o vi tri le trong day la uoc cua ',k,' la: ',t3);
dem4:=0;
t4:=0;
for i:=1 to n do
if (a[i]+k=1) or (a[i]=k+1) then
begin
inc(dem4);
t4:=t4+a[i];
end;
writeln('So phan tu la anh em cua ',k,' trong day la: ',dem4);
writeln('Tong cac phan tu la anh em cua ',k,' trong day la: ',t4);
readln;
end.
Viết chương trình nhập vào từ bàn phím mảng B gồm N số nguyên (N<=200)và 1 số nguyên dương k:
1. Tính tổng các phần tử lẻ trong mảng A và đưa kết quả ra màn hình?
2. Tính tổng các phần tử là bội của K trong mảng A và đưa kết quả ra màn hình?
uses crt;
var a:array[1..200]of integer;
n,i,k,t,t1:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
write('Nhap k='); readln(k);
t:=0;
for i:=1 to n do
if a[i] mod 2<>0 then t:=t+a[i];
t1:=0;
for i:=1 to n do
if a[i] mod k=0 then t1:=t1+a[i];
writeln('Tong cac phan tu le la: ',t);
writeln('Tong cac phan tu la boi cua ',k,' la: ',t1);
readln;
end.
Viết chương trình nhập vào từ bàn phím các số nguyên dương, khi người dùng nhập số có nhiều chữ số, thì chương trình sẽ tính tổng của các chữ số đó và in ra màn hình. (dùng Python để viết chương trình).
Ví dụ: khi người dùng nhập số 246 thì tổng bằng 2 + 4 + 6 = 12
tin học: C1 viết phương trình nhập số nguyên dương a có 3 chữ số .tính tổng các chữ số của a
C2: viết chương trình nhập từ bàn phím một số nguyên x. hãy tính và đưa ra màn hình giá trị của hàm f(x)= x^10+5x+1
Câu 1:
#include <bits/stdc++.h>
using namespace std;
long long n;
int main()
{
cin>>n;
int t=0;
while (n>0)
{
int x=n%10;
t=t+x;
n=n/10;
}
cout<<t;
return 0;
}
viết chương trình cho người dùng nhập vào một số nguyên dương lớn hơn 2 và đưa ra màn hình các số là ước của số nguyên đó.
Pascal / Viết Chương trình nhập vào và đưa ra màn hình cách đọc các chữ số tương ứng với số đó
VD: Nhập vào số "12345" ;Xuất ra màn hình "một hai ba bốn năm"
mong mn chịu khó giúp :(
Program HOC24;
var i: byte;
s: string;
begin
readln(s);
for i:=1 to length(s) do
begin
if s[i]='1' then write('mot ');
if s[i]='2' then write('hai ');
if s[i]='3' then write('ba ');
if s[i]='4' then write('bon ');
if s[i]='5' then write('nam ');
if s[i]='6' then write('sau ');
if s[i]='7' then write('bay ');
if s[i]='8' then write('tam ');
if s[i]='9' then write('chin ');
if s[i]='0' then write('khong ');
readln;
end.
Giúp với tớ cần gấp viết chương trình cho người dùng nhập vào một số nguyên dương lớn hơn 2 và đưa ra màn hình các số là ước của số nguyên đó.
Var n,i:integer;
Begin
n:=0;
White n<=2 do
Begin
Write('Nhap so n > 2, n = ');readln(n);
End;
Write('Cac uoc cua ',n,' la ');
For i:=1 to n do
If n mod i = 0 then write(i,' ');
Readln;
End.
Đề 1. Viết phương trình nhập hai số nguyên a và b hoán vị hai số đó khi a>b đưa ra màn hình Đề 2.Viết phương trình nhập số nguyên dương n in ra tổng các số nguyên dương là bội của 3 và 5
Bài 2:
uses crt;
var n,i,t:integer;
begin
clrscr;
readln(n);
t:=0;
for i:=1 to n do
if (i mod 3=0) and (i mod 5=0) then t:=t+i;
writeln(t);
readln;
end.