Viết chương trình tính tổng của 2 số nguyên x, y. Có sử dụng hàm
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.
![](https://rs.olm.vn/images/avt/0.png?1311)
![](https://rs.olm.vn/images/avt/0.png?1311)
uses crt;
var x,y:integer;
{-------------------chuong-trinh-con-tong----------------------------}
function tong(a,b:integer):integer;
begin
tong:=a+b;
end;
{-------------------chuong-trinh-con-hieu----------------------------}
funtion hieu(a,b:integer):integer;
begin
hieu:=a-b;
end;
{-------------------chuong-trinh-con-tich----------------------------}
function tich(a,b:integer):integer;
begin
tich:=a*b;
end;
{-------------------chuong-trinh-con-thuong----------------------------}
function thuong(a,b:integer):real;
begin
thuong:=a/b;
end;
{----------------------chuong-trinh-chinh-----------------------}
begin
clrscr;
write('Nhap x='); readln(x);
write('Nhap y='); readln(y);
writeln('Tong la: ',tong(x,y));
writeln('Hieu la: ',hieu(x,y));
writeln('Tich la: ',tich(x,y));
writeln('Thuong la: ',thuong(x,y):4:2);
readln;
end.
![](https://rs.olm.vn/images/avt/0.png?1311)
c++:
#include <iostream>
using namespace std;
int main(){
int y;
cin >> y;
int i = 1;
int luythua = 1;
while(i<=y){
luythua = luythua *i;
i = i+1;
}
cout << luythua;
}
![](https://rs.olm.vn/images/avt/0.png?1311)
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.
![](https://rs.olm.vn/images/avt/0.png?1311)
#include <bits/stdc++.h>
using namespace std;
long long n,i,x,t;
int main()
{
cin>>n;
t=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x<0) t+=x;
}
cout<<t;
return 0;
}
![](https://rs.olm.vn/images/avt/0.png?1311)
![](https://rs.olm.vn/images/avt/0.png?1311)
uses crt;
var a,b,c,d:integer;
{-------------------chuong-trinh-con-----------------------}
function max(x,y:integer):integer;
begin
if x<y then max:=y
else max:=x;
end;
{----------------------chuong-trinh-chinh----------------------}
begin
clrscr;
write('a='); readln(a);
write('b='); readln(b);
write('c='); readln(c);
write('d='); readln(d);
writeln(max(a,max(b,max(c,d))));
readln;
end.
uses crt;
var x,y:integer;
//chuongtrinhcon
function tong(a,b:integer):integer;
begin
tong:=a+b;
end;
//chuongtrinhchinh
begin
clrscr;
readln(x,y);
writeln(tong(x,y));
readln;
end.