K
Khách

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.

Bài 4: 

#include <bits/stdc++.h>

using namespace std;

long long a[1000],i,n;

int main()

{

cin>>n;

for (i=1; i<=n; i++) cin>>a[i];

sort(a+1,a+n+1);

cout<<"So lon nhat la: "<<a[n]<<endl;

cout<<"So nho nhat la: "<<a[1]<<endl;

cout<<"So lon thu hai la: "<<a[n-1]<<endl;

cout<<"So nho thu hai la: "<<a[2];

return 0;

}

2 tháng 1 2022

viết bằng pascal được không bạn?

 

uses crt;

var a:array[1..100]of integer;

i,n,tam,j:integer;

{---------------chuong-trinh-con----------------------}

procedure hoandoi(x,y:integer);

var tam:integer;

begin

tam:=x;

x:=y;

y:=tam;

end;

{--------------------chuong-trinh-chinh---------------------------}

begin

clrscr;

write('Nhap n='); readln(n);

for i:=1 to n do 

  begin

write('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

begin

hoandoi(a[i],a[j]);

end;

for i:=1 to n do 

  write(a[i]:4);

readln;

end.

uses crt;

var a,b,c:array[1..1000]of integer;   

i,n,dem,max:integer;

begin

clrscr;

write('Nhap n='); readln(n);

for i:=1 to n do 

begin     

write('A[',i,']='); readln(a[i]); 

end;

dem:=0;

max:=a[1];

for i:=1 to n do 

if max<a[i] then max:=a[i];

for i:=1 to n do 

if max=a[i] then     

begin       

inc(dem);       

b[dem]:=a[i];       

c[dem]:=i;     

end;

if dem=1 then writeln('So lon nhat la: ',b[dem],' vi tri la: ',c[dem])

else writeln('So lon nhat la: ',b[1],' vi tri la: ',c[1]);

readln;

end.

25 tháng 2 2021

Bọn em học C++ ạ :<<

 

Câu 2: 

uses crt;

var a,b:integer;

{-----------------chuong-trinh-con-------------------}

function ucln(x,y:integer):integer;

var i,uc:integer;

begin

if x<y then 

begin

uc:=1;

for i:=1 to x do 

  if (x mod i=0) and (y mod i=0) then  

begin

if uc<i then uc:=i;

end;

end

else begin

uc:=1;

for i:=1 to y do 

  if (x mod i=0) and (y mod i=0) then  

begin

if uc<i then uc:=i;

end;

end;

ucln:=uc;

end;

{--------------------------chuong-trinh-chinh------------------------}

begin

clrscr;

write('Nhap a='); readln(a);

write('Nhap b='); readln(b);

writeln(a,'/',b,'=',a div ucln(a,b),'/',b div ucln(a,b));

readln;

end.

Câu 1: 

const fi='songuyen.inp';

fo='tong.out';

var f1,f2:text;

a:array[1..100]of integer;

i,n,t:integer;

begin

assign(f1,fi); reset(f1);

assign(f2,fo); rewrite(f2);

n:=0;

while not eoln(f1) do 

  begin

n:=n+1;

read(f1,a[n]);

end;

t:=0;

for i:=1 to n do 

  if a[i] mod 2=0 then t:=t+a[i];

writeln(f2,t);

close(f1);

close(f2);

end.

4 tháng 1 2017

a)

uses crt;

VAR

n, d, i: integer;

BEGIN

clrscr;

Writeln ('Nhap vao n='); readln (n);

d : = 1;

For i: = 1 to n do

d: = d*i;

Writeln ('d=',d);

Readln;

END.

c)

uses crt;

VAR

n, i, demuoc: integer;

BEGIN

clrscr;

Writeln ('Nhap vao n='); readln (n);

demuoc: = 0;

For i: = 1 to n do

If n mod i = 0 then

demuoc : = demuoc + 1;

If demuoc = 2 then

Writeln ('n la so nguyen to')

ELSE

Writeln ('n khong phai la so nguyen to');

Readln ;

END.

Còn phần b bạn tự nghĩ nha!

Chúc bạn học tốt!

24 tháng 12 2021

#include <bits/stdc++.h>

using namespace std;

long long a[6],i,t,t1;

int main()

{

t=0;

for (i=1; i<=n; i++)

{

cin>>a[i];

if (a[i]%2==0) t=t+a[i];

}

t1=0;

for (i=1; i<=n; i++)

if ((a[i]%2!=0) and (i%2==0)) t1=t1+a[i];

cout<<t<<endl;

cout<<t1;

return 0;

}

27 tháng 12 2021

#include <bits/stdc++.h>

using namespace std;

long long a[1000],i,n,vt,nn;

int main()

{

cin>>n;

for (i=1; i<=n; i++) cin>>a[i];

nn=a[1];

for (i=1; i<=n; i++) nn=min(nn,a[i]);

vt=0;

for (i=1; i<=n; i++) if (min==a[i]) vt=i;

cout<<nn<<endl;

cout<<vt;

return 0;

}

#include <bits/stdc++.h>

using namespace std;

long long a,b;

int main()

{

freopen("sn.inp","r",stdin);

freopen("cn.out","w",stdout);

cin>>a>>b;

cout<<a*b;

return 0;

}