วันอังคารที่ 23 กันยายน พ.ศ. 2551

การเขียนโปรเเกรม

1.พัฒนาโปรแกรมเครื่องคิดเลข โดยให้ผู้ใช้ป้อนตัวเลข 2 จำนวน และเลือกเครื่องหมาย แล้วทำการแสดงผลลัพธ์ออกทางจอภาพ ดังตัวอย่างจอภาพ (Filename : cal.cpp
#include
#include
void main()
{
char op;
float a,b;
clrscr();
printf("Input First Number : ");scanf("%f",&a);
printf("\nInput Operator(+,-,*,/) : ");scanf("%s",&op);
printf("\nInput Second Number : ");scanf("%f",&b);
switch(op)
{
case '+': printf("\n%0.2f + %0.2f = %0.2f",a,b,a+b);break;
case '-': printf("\n%0.2f - %0.2f = %0.2f",a,b,a-b);break;
case '*': printf("\n%0.2f * %0.2f = %0.2f",a,b,a*b);break;
case '/': printf("\n%0.2f / %0.2f= %0.2f",a,b,a/b);break;
default: printf("\nPlease seleec choice (+,-,*,/)");
getch();
}

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