Viết chương trình nhập vào 2 số nguyên dương a và b. Hỏi tổng số là bao nhiêu?
Hãy nhập câu hỏi của bạn vào đây, nếu là tài khoản VIP, bạn sẽ được ưu tiên trả lời.
Var a:array[1..1000] of integer;
i,n,d:integer;
sd,s:longint;
Begin
Write('n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap phan tu thu ',i,' = ');readln(a[i]);
s:=s+a[i];
End;
For i:=1 to n do
If a[i] > 0 then
Begin
d:=d+1;
sd:=sd+a[i];
End;
Writeln('Tong cac so vua nhap la ',s);
Write('Co ',d,' so nguyen duong va tong cua chung la ',sd);
Readln
End.
Tham khảo:
uses crt;
Var a,b,i : Integer ;
Begin
Clrscr ;
Write ('Nhap a: '); readln (a);
Write ('Nhap b: '); readln (b);
i:=a + b;
If i mod 2 = 0 then writeln ('Tong hai so ',a,' va ',b,' la ',i,', day la mot so chan')
Else writeln ('Tong hai so ',a,' va ',b,' la ',i,', day la mot so le');
Readln ;
End.
#include <bits/stdc++.h>
using namespace std;
long long a,b,t;
int main()
{
cin>>a>>b;
t=a+b;
if (t>0) cout<<"Tong la so duong";
else if (t<0) cout<<"Tong la so am";
else cout<<"Tong la so 0";
cout<<endl;
if (t%2==0) cout<<"Tong co chia het cho 2";
else cout<<"Tong khong chia het cho 2";
return 0;
}
uses crt;var n: longint; chrn: string; valn,sum,max,i,preperror: byte;begin write('Nhap so can kiem tra: '); readln(n); str(n,chrn); for i:=1 to length(chrn) do begin val(chrn[i],valn,preperror); sum:=sum+valn; if max<valn then max:=valn; valn:=0 end; writeln('Ket qua: '); writeln(length(chrn)); writeln(sum); write(max); readln;end.uses crt;var n: longint; chrn: string; valn,sum,max,i,preperror: byte;begin write('Nhap so can kiem tra: '); readln(n); str(n,chrn); for i:=1 to length(chrn) do begin val(chrn[i],valn,preperror); sum:=sum+valn; if max<valn then max:=valn; valn:=0 end; writeln('Ket qua: '); writeln(length(chrn)); writeln(sum); write(max); readln;end.
Program HOC24;
var N:longint;
max,tg,t,d: integer;
Begin
write('Nhap N : '); readln(N);
max:=0;
while n<>0 do
begin
tg:=n mod 10;
d:=d+1;
t:=t+tg;
if tg>max then max:=tg;
n:=n div 10;
end;
writeln('So nguyen N co ',d,' chu so');
writeln('Tong cac chu so cua N la : ',t);
write('Chu so lon nhat cua N la :',max);
readln
end.
Câu 1:
uses crt;
var a,b:integer;
begin
clrscr;
readln(a,b);
write(a+b);
readln;
end.
Câu 2:
uses crt;
var a,b,c:integer;
begin
clrscr;
readln(a,b,c);
writeln(a+b-c);
readln;
end.
Câu 3:
uses crt;
var a,b:integer;
begin
clrscr;
readln(a,b);
writeln(a-b);
readln;
end.
Câu 4:
uses crt;
var x,y,z:integer;
begin
clrscr;
readln(x,y,z);
writeln((x+y)*z);
readln;
end.
a)
uses crt;
VAR
n, d, i: integer;
BEGIN
clrscr;
Writeln ('Nhap vao n='); readln (n);
d : = 1;
For i: = 1 to n do
d: = d*i;
Writeln ('d=',d);
Readln;
END.
c)
uses crt;
VAR
n, i, demuoc: integer;
BEGIN
clrscr;
Writeln ('Nhap vao n='); readln (n);
demuoc: = 0;
For i: = 1 to n do
If n mod i = 0 then
demuoc : = demuoc + 1;
If demuoc = 2 then
Writeln ('n la so nguyen to')
ELSE
Writeln ('n khong phai la so nguyen to');
Readln ;
END.
Còn phần b bạn tự nghĩ nha!
Chúc bạn học tốt!
Bài 1:
uses crt;
var n,i,s:integer;
begin
clrscr;
write('Nhap n='); readln(n);
s:=0;
for i:=1 to n do
if i mod 6=0 then s:=s+i;
writeln(s);
readln;
end.
Bài 2:
uses crt;
var a,b,c,ucln,i:integer;
begin
clrscr;
write('a='); readln(a);
write('b='); readln(b);
write('c='); readln(c);
while a<>b do
begin
if a>b then a:=a-b
else b:=b-a;
end;
ucln:=a;
while ucln<>c do
begin
if ucln>c then ucln:=ucln-c
else c:=c-ucln;
end;
writeln(ucln);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long a,b,c;
int main()
{
cin>>a>>b>>c;
cout<<a+b+c<<endl;
cout<<a*b*c;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
long long a,b,c;
int main()
{
cin>>a>>b>>c;
cout<<a+b+c<<endl;
cout<<a*b*c;
return 0;
}
program cau_1;
uses crt;
var a,b,s:integer;
begin
clrscr;
write('nhap so a:'); readln(a);
writeln('nhap so b:');readln(b);
s:=0;
s:=a+b;
writeln('tong hai so a, b la:',s);
readln;
end.
jj