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.
program tinhtong;
uses crt;
var i, n, s: integer;
begin clrscr;
Write('N so tu nhien dau tien la: ');
readln(n);
s:=0;
i:=1;
while i<=n do begin
s:=s+i;
i:=i+1;
end;
writeln('Tong cac so la: ',s);
readln
end.
giúp mình câu này luôn nhé
In ra màn hình trung bình của cấc số đã cho ở trên.
liên quan bài trên
Câu 1:
uses crt;
var n,i,dem,j,kt1,kt2,a,b,kt:integer;
begin
clrscr;
write('Nhap n='); readln(n);
dem:=0;
if n mod 2=1 then
begin
a:=2;
b:=n-a;
kt:=0;
for i:=2 to trunc(sqrt(b)) do
if b mod i=0 then kt:=1;
if kt=0 then inc(dem);
end
else begin
for i:=2 to n div 2 do
begin
a:=i;
b:=n-i;
kt1:=0;
kt2:=0;
for j:=2 to trunc(sqrt(a)) do
if a mod j=0 then kt1:=1;
for j:=2 to trunc(sqrt(b)) do
if b mod j=0 then kt2:=1;
if (kt1=0) and (kt2=0) then inc(dem);
end;
end;
writeln('So cach phan tich ',n,' thanh tong hai so nguyen to la: ',dem);
readln;
end.
Câu 2:
uses crt;
var n,x:integer;
{-----------------ham-kiem-tra-nguyen-to-----------------}
function ktnt(x:integer):boolean;
var kt:boolean;
i:integer;
begin
kt:=true;
for i:=2 to trunc(sqrt(x)) do
if x mod i=0 then
begin
kt:=false;
break;
end;
if kt=true then ktnt:=true
else ktnt:=false;
end;
{---------------ham-kiem-tra-so-doi-xung---------------}
function ktdx(x:integer):boolean;
var kt:boolean;
d,i:integer;
st:string;
begin
str(x,st);
d:=length(st);
kt:=true;
for i:=1 to d do
if st[i]<>st[d-i+1] then
begin
kt:=false;
break;
end;
if kt=true then ktdx:=true
else ktdx:=false;
end;
{--------------chuong-trinh-chinh---------------}
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until n>0;
if (ktnt(n)=true) and (ktdx(n)=true) then writeln(n,' la so nguyen to doi xung')
else writeln(n,' khong la so nguyen to doi xung');
x:=n+1;
repeat
x:=x+1;
until (ktnt(x)=true) and (ktdx(x)=true);
writeln('So nguyen to doi xung nho nhat lon hon ',n,' la: ',x);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
int main ()
{
int a[32];
int n,i,s;
cout<<"nhap so phan tu cua mang ";
cin>>n;
cout<<"nhap cac phan tu cua mang ";
for (i=1; i<=n; i++)
{
s=0;
cin>>a[i];
}
for(i=1; i<=a[i]; i++) s=s+i;
cout<<s;
return 0;
}
uses crt;
var a:array[1..100]of integer;
i,n,t:integer;
s:real;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
s:=1;
for i:=1 to n do
s:=s*a[i];
writeln('Tich la: ',s:0:0);
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln('Trung binh la: ',t/n:4:2);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long a;
int main()
{
cin>>a;
if (a%2==0) cout<<a<<" la so chan";
else cout<<a<<" la so le";
return 0;
}
Var s,n,i,so:integer;
Begin
Write('Nhap so luong so n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap so thu ',i)readln(so);
If so mod 2 = 0 then s:=s+so;
End;
Write('Tong cac so chan la ',s);
Readln;
End.
#include <bits/stdc++.h>
using namespace std;
int n,kt,t;
int main()
{
cin>>n;
int t=0;
for (int i=1; i<=n; i++)
if (i%2==1) cout<<i<<" ";
cout<<endl;
for (int i=2; i<=n; i++)
{
kt=0;
for (int j=2; j*j<=i; j++)
if (i%j==0) kt=1;
if (kt==0) cout<<i<<" ";
}
return 0;
}
uses crt;
var a:integer;
begin
clrscr;
write('Nhap a='); readln(a);
if (a mod 3=0) and (a mod 5=0) then writeln(a,' dong thoi chia het cho 3 va 5')
else writeln('Khong thoa dieu kien');
readln;
end.