Nhập ba số từ bàn phím và đưa ra kết quả ba số theo thứ tự : số lớn, số bé hơn, số bé

2 câu trả lời

Program BTT;
Uses crt;
Var a,b,c: longint;
Begin
        Clrscr;
        Write('Nhap a, b, c: '); Readln(a,b,c);

        If (a<=b) and (b<=c) then Write(c,' ',b,' ',a);
        If (a<=c) and (c<=b) then Write(b,' ',c,' ',a);

        If (b<=a) and (a<=c) then Write(c,' ',a,' ',b);
        If (b<=c) and (c<=a) then Write(a,' ',c,' ',b);

        If (c<=b) and (b<=a) then Write(a,' ',b,' ',c);
        If (c<=a) and (a<=b) then Write(b,' ',a,' ',c);

        Readln
End.

#include <stdio.h> #inlcude <conio.h> int main(){ int a, b, c; // 3 số nguyên int temp;// biến tạm thời để giúp đổi chỗ (temporary) printf("Enter 3 integer a, b, c: "); scanf("%d %d %d", &a, &b, &c); // chuyển số bé nhất vào a if(a>b){ temp=a; a=b; b=temp; } if(a>c){ temp=a; a=c; c=temp; } // chuyển số bé nhì vào b if(b>c){ temp=b; b=c; c=temp; } printf("\n%d %d %d", a, b, c); getch(); return 0;

Câu hỏi trong lớp Xem thêm