Cho x, y là 2 số nguyên . Viết chương trình có sử dụng chương trình con để tính tổng, hiệu, tích, thương của 2 số đó
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.
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.
#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;
}
#include<iostream>
using namespace std;
int main() {
int x, y;
cout << "x : "; cin >> x;
cout << "y : "; cin >> y;
cout << "x + y = " << x + y;
cout << "x - y = " << x - y;
cout << "x * y = " << x * y;
cout << "x / y = " << x / y;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
long long a[1000],i,n,t;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
t=0;
for (i=1; i<=n; i++) t+=a[i];
cout<<t<<endl;
sort(a+1,a+n+1);
for (i=1; i<=n; i++) cout<<a[i]<<" ";
return 0;
}
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.
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.
Câu 3:
#include <bits/stdc++.h>
using namepsace std;
double a,b,c,p,s;
int main()
{
cin>>a>>b>>c;
p=(a+b+c)/2;
s=sqrt(p*(p-a)*(p-b)*(p-c));
cout<<fixed<<setprecision(2)<<s;
return 0;
}
Câu 3:
#include <bits/stdc++.h>
using namepsace std;
double a,b,c,p,s;
int main()
{
cin>>a>>b>>c;
p=(a+b+c)/2;
s=sqrt(p*(p-a)*(p-b)*(p-c));
cout<<fixed<<setprecision(2)<<s;
return 0;
}
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.