welcome

วันจันทร์ที่ 18 กรกฎาคม พ.ศ. 2554

BME240 week5 ข้อ 7

7.จงเขียนโปรแกรมเพื่่อรับค่าตัวเลข 1 จำนวนเพื่อตรวจสอบว่าเป็นเลขคู่ (Even number) หรือเป็นเลขคี่ (Odd number) จากนั้นให้ขึ้นข้อความ Do you want to continue ('Y/N') ? เพื่อถามว่าต้องการจะรับค่าตัวเลขถัดไปหรือไม่ ถ้าผู้ใช้กดปุ่ม Y จะให้มีการรับค่าตัวเลขถัดไป ถ้าผู้ใช้กดปุ่ม N โปรแกรมจะจบการทำงาน

#include<stdio.h>
#include<conio.h>
main()
{
      int num;
      char ans;
      do
      {
      printf("Enter Number : ");
      scanf("%d",&num);
            if(num%2==0)
            {
                  printf(" %d is even number",num);
            }
            else
            {
                  printf(" %d is odd number",num);
            }
      printf("\n Do you want to continue(Y/N) : ");
      ans=getche();
      printf("\n\n");
      }
      while(ans=='Y'||ans=='y');
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น