Viết chương trình Pascal nhập 10 giá trị nguyên, sau đó tìm giá trị lớn nhất, nhỏ nhất, sắp xếp mảng theo thứ tự tăng dần, giảm dần và hiển thị kết quả.

2 câu trả lời

#include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) {   int arr[10];   int mode[10][2];    cout<<"Nhap 10 so nguyen\n";   for(int l=0;l<10;l++) {     cout<<"Gia tri "<<l<<" la :";cin>>arr[l]; }   //tim gia tri lon nhat va nho nhat  int i,j,temp; //sap xep mang de tim gia tri lon nhat va nho nhat  for(i=0;i<10;i++)  for(j=9;j>i;j--)     if(arr[j]<arr[j-1]) {         int temp=arr[j];          arr[j]=arr[j-1];          arr[j-1]=temp;}                    cout<<"Gia tri lon nhat="<<arr[9]<<"\nGia tri nho nhat="<<arr[0];   cout<<"\n"; //khoi tao mang 2 chieu de sap xep tan suat va gia tri for(i=0;i<2;i++)    for(j=0;j<10;j++)mode[j][i]=0;      mode[0][0]=1;   //tim tan suat  for(i=0;i<10;i++)   for(j=0;j<10;j++)    if(arr[i]==arr[j+1]) {++mode[i][0];mode[i][1]=arr[i];}    //tim so lan suat hien nhieu nhat int max; int k=0; max=mode[0][0];    for(j=0;j<10;j++)     if(max<mode[j][0]){max=mode[j][0];k=j;}     //in ket qua   cout<<"Gia tri xuat hien nhieu nhat la:"<<mode[k][1]<<"\n";   cout<<"Xuat hien "<<max<<" lan.";   cout<<"\n";     return 0; }

uses crt;
var a : array[1..100] of integer;
i , h, k, n, max, min , q, p  : integer;
begin
clrscr;
write(' nhap so n :'); readln(n);
for i := 1 to n do
begin
write('nhap so nguyen thu ', i ,' : ');readln(a[i]);
end;
max:= a[1];
for i := 2 to n  do
if a[i] > max then max := a[i];
min := a[1];
for i := 2 to n do 
if a[i] < min then min:= a[i];
writeln('gia tri lon nhat : ', max);
writeln('gia tri nho nhat : ', min);
writeln;
For h :=1 to n - 1 do
For k := h + 1 to n do
If a[h] < a[k] Then
begin
a[h] := a[h] + a[k];
a[k] := a[h] - a[k];
a[h] := a[h] - a[k];
end;
write('day sap xep theo thu tu giam dan la :');
for h := 1 to n do write(a[h]:4);
writeln;
For p := 1 to n - 1 do
For q := p + 1 to n do
If a[p] > a[q] Then
begin
a[p] := a[p] + a[q];
a[q] := a[p] - a[q];
a[p] := a[p] - a[q];
end;
write('day sap xep theo thu tu tang dan la :');
for p := 1 to n do write(a[p]:4);
end.

Câu hỏi trong lớp Xem thêm
4 lượt xem
2 đáp án
12 giờ trước

giup e voi I/ Supply the correct form of the verbs in brackets 1. You (think) ……………………… collecting stamps costs much money? 2. Every year, my mother (give) ……………………… me a nice doll on my birthday. 3. Jenny says she loves collecting pens but she (not/continue) ……………………… this hobby from next year. 4. If you wash your hands more, you (have)……………………. less chance of catching flu. 5. Getting plenty of rest is very good. It (help)…………………. you to avoid depression. 6. Mr. John (be) ……………………… principal of our school since last year. 7. I (see) ……………………… a car accident on this corner yesterday. 8. We like (come)……………………to school by bus, but we hate (stand)………………………. and (wait) …………………… in the rain. 9. ……………………… (you/ ever/ meet) anyone famous? 10. My mother (come) ……………………… to stay with us next weekend. 11. When he lived in Manchester, he (work) ……………………… in a bank. 12. We (be) ……………………… students for four years. 13. We are planting trees around our school now. Our school (be) ……………………… surrounded by a lot of green trees. 14. What ……………………… your father usually ……………………… (do) in the evenings? 15. My sister likes (cook) ……………………… very much. She can cook many good foods. 16. My father says when he's retired, he (go) …………………… back to his village to do the gardening. 17. They want (buy) ……………………… some meat for dinner. 18. Linh is my best friend. We (know) ……………………… each other for 5 years. 19. I enjoy (fish) ……………………… because it is relaxing. 20. How about (go) ……………………… to the movie theatre?

3 lượt xem
1 đáp án
1 ngày trước