แบบฝึกหัดที่ 5

จงเขียนฟังก์ชั่น compare เพื่อทำการเปรียบเทียบ จำนวนเต็ม 2 จำนวน (x,y) และแสดงผลออกจอภาพ โดยถ้า x เท่ากับ y จะแสดงคำว่า Equal ออกจอภาพ
x น้อยกว่า y จะแสดงคำว่า Less than ออกจอภาพ
x มากกว่า y จะแสดงคำว่า More than ออกจอภาพ
ซึ่งฟังก์ชั่น มีการเรียกใช้งานดังนี้ compare(5,7);
#include
#include
int compare(x,y);
int main(void)
{
int x,y;
printf("Input 2 integers :");
scanf("%d %d",&x,&y);
compare(x,y);
return 0;
}
compare(x,y)
{
if(x==y)
{
printf("EQUAL !");
}
if(x<0)
{
if(y<0)
{
x = abs(x);
y = abs(y);
if(xy)
printf("Less than!");
}
else
printf("Less than!");
}
if(y<0)
{
if(x<0)
{
x = abs(x);
y = abs(y);
if(xy)
printf("Less than");
}
else
printf("More than!");
}
else
if(x>y)
printf("More than");
if(x

10 ความคิดเห็น:

  1. เกิดไรขึ้นไม่รู้ พิมแล้วส่วนท้ายไม่ครบ

    ตงinclude วงเล็บก้อหายอ่ะ

    ตอบลบ
  2. ตรง include หายทุกคนเลย

    ตอบลบ
  3. แก้ไข ต่อจากในตัวอย่างน่ะ เพิ่ม บรรทัดต่อไม่ได้ เพราะอะไร

    ต่อจากบรรทัดล่างสุด
    if(x<y)
    printf("less than");

    }

    ตอบลบ
  4. อันนี้ง่ายตะหากแฮม :))

    ตอบลบ
  5. โหยทั้งยากทั้งยาวว

    ตอบลบ