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.
Câu 2:
#include <bits/stdc++.h>
using namespace std;
long long n;
int main()
{
cin>>n;
if (n>0 && n%5==0) cout<<"Phai";
else cout<<"Khong phai";
}
var i,n,s:integer;
begin
write('nhap n = ');readln(n);
i:=1;
while i<=n do
begin
s:=s+i;
i:=i+1;
end;
write('Tong la ',s);
readln;
end.
*while..do
Program HOC24;
var i,n: integer;
s: real;
begin
write('Nhap n: '); readln(n);
i:=1;
while i<=n do
begin
s:=s+1/sqr(i);
i:=i+1;
end;
write('S= ',s:6:2);
readln
end.
program tinhtong;
var n,i : integer;
S : real;
begin
write('Nhap n: ');
readln(n);
i:=1;
S:=0;
while i<=n do
begin
S:=S+1/i;
i:=i+1;
end;
writeln('Tong S= ',S);
readln;
end.
program tinh_tong_S;
var
n, i: integer;
S: real;
begin
write('Nhap n: ');
readln(n);
S := 0;
i := 1;
while i <= n do
begin
S := S + 1 / i;
i := i + 1;
end;
writeln('Tong S la: ', S:0:2);
readln;
end.
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.
Cách 1 dùng lệnh for do:
Uses crt;
var i,n,k: integer;
begin clrcsr;
readln(n);
for i:=1 to n do begin
if(i mod 2=0) and (i>=10) then k:=k*i;
end;
writeln(k);
readln;
end.
Cách 2 dùng lệnh while do
Uses crt;
var m,n,o: integer;
begin clrcsr;
readln(n);
o:=1;
m:=1;
while (m<n) do begin
m:=m+1;
if(m mod 2=0) and (m>=10) then o:=o*m;
end;
writeln(o);
readln;
end.
Bài 2:
#include <bits/stdc++.h>
using namespace std;
long long x,y;
int main()
{
cin >>x>>y;
cout<<x<<" "<<y;
swap(x,y);
cout<<x<<" "<<y;
return 0;
}
program Le_Nho_Hon_Hoac_Bang_n;
uses crt;
var
n, i: integer;
begin
clrscr;
write('Nhap vao mot so nguyen duong n: ');
readln(n);
while n <= 0 do
begin
writeln('So ban nhap khong hop le. Xin vui long nhap lai: ');
readln(n);
end;
clrscr;
writeln('Cac so le nho hon hoac bang ', n, ' la:');
i := 1;
while i <= n do
begin
if i mod 2 <> 0 then
writeln(i);
i := i + 1;
end;
readln;
end.
program tim_max;
uses crt;
var i,n,max:integer;
x:array[1..100]of byte;
begin
clrscr;
write('nhap so n:');readln(n);
i:=1;
while i<=n do
begin
write('x[',i,']=');readln(x[i]);
i:=i+1;
end;
max:=x[1];i:=1;
while i<=n do
begin
if max<x[i] then max:=x[i];
i:=i+1;
end;
write('so lon nhat la:',max);
readln;
end.