1. viết chương trình in ra màn hình các số từ 100 đến 1 theo thứ tự giảm dần (hoặc ngược lại), mỗi số cách nhau 3 đơn vị
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.
1)
Var array:[1..1000] of integer;
i,n,t:integer;
Begin
Write('n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap so thu ',i,' = ');readln(a[i]);
End;
For i:=1 to n do
If a[i] > a[i+1] then
Begin
t:=a[i];
a[i]:=a[i+1];
a[i+1]:=t;
End;
Write('Sap xep tang dan ');
For i:=1 to n do write(a[i]:8);
Readln
End.
2)
Var array:[1..1000] of integer;
i,n,t:integer;
Begin
Write('n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap so thu ',i,' = ');readln(a[i]);
End;
For i:=1 to n do
If a[i] < a[i+1] then
Begin
t:=a[i];
a[i]:=a[i+1];
a[i+1]:=t;
End;
Write('Sap xep giam dan ');
For i:=1 to n do write(a[i]:8);
Readln
End.
uses crt;
var a:array[1..100]of integer;
n,i,t,nn,kt:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
t:=1;
for i:=1 to n do
if a[i] mod 3=0 then t:=t*a[i];
writeln(t);
kt:=0;
nn:=32567;
for i:=1 to n do
if a[i] mod 3=0 then
begin
if nn>a[i] then nn:=a[i];
kt:=1;
end;
if kt=0 then writeln('Khong co so chia het cho 3')
else writeln('So nho nhat chia het cho 3 la: ',nn);
for i:=1 to n do
if nn=a[i] then write(i:4);
writeln;
for i:=n downto 1 do
write(a[i]:4);
readln;
end.
#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;
}
Chắc chắn rồi, đây là code C++ để đếm ngược từ N về 0:
C++
#include <iostream>
int main() {
int n;
std::cout << "Nhập số nguyên N: ";
std::cin >> n;
for (int i = n; i >= 0; i--) {
std::cout << i << std::endl;
}
return 0;
}
Input:
Nhập số nguyên N: 5
Output:
5
4
3
2
1
0
Giải thích:
Code sử dụng vòng lặp for để lặp từ n đến 0, với mỗi vòng lặp, in ra giá trị của biến i.
Bạn có thể thay đổi input để kiểm tra xem chương trình có hoạt động chính xác hay không.
uses crt;
var i:integer;
begin
clrscr;
for i:=20 downto 1 do
write(i:4);
readln;
end.
Câu 1:
Program HOC24;
var i,p: integer;
t: longint;
begin
write('Nhap P: '); readln(p);
t:=0;
for i:=1 to p do if i mod 2<>0 then t:=t+i;
write('Tong cac so le la: ',t);
readln
end.
#include <bits/stdc++.h>
using namespace std;
long long a[10000],i,n,dem;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
dem=0;
for (i=1; i<=n; i++)
if (a[i]%3==0)
{
cout<<a[i]<<" ";
dem++;
}
cout<<endl;
cout<<dem;
return 0;
}
Program HOC24;
var t: integer;
begin
t:=103;
while t<>1 do
begin
t:=t-3;
write(t,' ');
end;
readln
end.