Viết Chương Trình Nhập Vào Từ Bàn Phím 2 Số Nguyên Khác Nhau , Sau Đó In Ra Màn Hình Với Thứ Tự Không Giảm
Câu 15. (1 điểm)Viết chương trình nhập vào 2 số nguyên a và b khác nhau từ bàn phím, in 2 số đó ra màn hình theo thứ tự không giảm
Viết chương trình nhập 2 số nguyên a và b khác nhau từ bàn phím và in ra 2 số đó ra màn hình thao thứ tự: A) Tăng dần B) Giảm dần
#include <bits/stdc++.h>
using namespace std;
long long a,b;
int main()
{
cin>>a>>b;
cout<<min(a,b)<<" "<<max(a,b)<<endl;
cout<<max(a,b)<<" "<<min(a,b)<<endl;
return 0;
}
Viết chương trình pascal nhập vào một mảng số nguyên B số lượng phần tử là m nhập từ bàn phím
+ sắp xếp mảng theo thứ tự giảm dần rồi in mảng đã sắp xếp ra màn hình
Var a:array[1..1000] of integer;
i,m,tam:integer;
Begin
Write('m = ');readln(m);
For i:=1 to m do
Begin
Write('Nhap so thu ',i,' = ');readln(a[i]);
End;
For i:=1 to m do
If a[i] < a[i+1] then
Begin
tam:=a[i];
a[i]:=a[i+1];
a[i+1]:=tam;
End;
Write('Mang sau khi sap xep: ');
For i:=1 to m do
Write(a[i]:8);
Readln;
End.
Mng giúp mình các BT cuối kì vs ạ Bài 1: Viết chương trình nhập từ bàn phím 2 số nguyên a,b; Sau đó ghi chúng vào tệp có tên D:\Baitaptin.txt. Bài 2: Viết chương trình nhập từ bàn phím 1 xâu không quá 180 kí tự; Xuất xâu vừa nhập ra màn hình rồi ghi xâu đó vào tệp có tên E:\tepxau.txt. Bài 3: Viết chương trình nhập từ bàn phím 2 số nguyên dương; Tính và ghi tổng của chúng vào tệp có tên ‘teptong.txt’ rồi xuất tổng ra màn hình.
Bài 3:
uses crt;
const fi='teptong.txt'
var a,b:integer;
f1:text;
begin
clrscr;
assign(f1,fi); rewrite(f1);
readln(a,b);
writeln(a+b);
writeln(f1,a+b);
close(f1);
readln;
end.
1. Viết chương trình tính tổng 2 số nguyên a, b.
2. Viết chương trình tính diện tích hình tròn với bán kính r nhập từ
bàn phím.
3. Viết chương trình nhập vào 1 ký tự. In ra màn hình vị trí ký tự đó
trong bảng mã ASCII
1:
#include <bits/stdc++.h>
using namespace std;
long long a,b;
int main()
{
cin>>a>>b;
cout<<a+b;
return 0;
}
2:
#include <bits/stdc++.h>
using namespace std;
double s,r;
int main()
{
cin>>r;
s=r*r*pi;
cout<<fixed<<setprecision(2)<<s;
return 0;
}
Viết chương trình in ra màn hình máy tính các số tự nhiên >0 với số đó là một số nguyên bất kỳ được nhập vào từ bàn phím.
nhập vào từ bàn phím một dãy số nguyên(sử dụng chương trình con), tính tổng các phần tử đó, in ra màn hình( sử dụng chương trình con), sắp xếp dãy số nguyên thành dãy không giảm(sử dụng chương trình con)
#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;
}
a) viết chương trình nhập N số nguyên từ bàn phím và in ra màn hình số nhỏ nhất.
b) viết chương trình nhập N số nguyên từ bàn phím và in ra màn hình số lớn nhất.
program hello;
uses crt;
Var n,i,j,k: integer;
a: array[1..50] of integer;
begin;
a[1]:=k;
Readln(n);
For i:=1 to n do
Begin;
Writeln('nhap a[',i,'] '); Readln(a[i]);
End;
For i:=1 to n-1 do
For j:=i+1 to n do
If a[i]<a[j] then k:=a[j];
Writeln('gia tri lon nhat la', k);
end.
1. Hãy nhập từ bàn phím 1 dãy số nguyên không âm. Hãy viết chương trình in ra màn hình chỉ số i nhỏ nhất sao chi tổng các phần tư từ 1 đến i lớn hơn 100
2. Hãy viết chương trình pascal để thực hiện các nhiệm vụ sau đây:
- Nhập vào từ bàn phím 1 dãy số không quá 30 số nguyên
- Kiểm tra rồi cho biết dãy số vừa nhập có phải là dãy số không giảm hay không
1. uses crt;
var a,vt:array[1..100]of integer;
n,i,t,dem:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
repeat
write('A[',i,']='); readln(a[i]);
until a[i]>=0;
end;
t:=0;
for i:=1 to n do
begin
if t<100 then
begin
t:=t+a[i];
dem:=dem+1;
vt[dem]:=i;
end;
end;
writeln(vt[dem]);
readln;
end.
Câu 2:
uses crt;
var a:array[1..30]of integer;
i,n,kt:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
kt:=0;
for i:=1 to n-1 do
if a[i]>=a[j] then kt:=1;
if kt=0 then writeln('Day la day so khong giam')
else writeln('Day khong la day so khong giam');
readln;
end.