10 ตุลาคม 2551

โปรแกรม สำหรับคำนวณน้ำหนักมาตรฐาน

#include
#include
void main()
{
float weight,height,standard;
char gender,name[30];
    clrscr();
    printf("Input Name     : ");scanf("%s",&name);
    printf("Input Height   : ");scanf("%f",&height);
    printf("Input Weight   : ");scanf("%f",&weight);
    printf("Input Gender   : ");scanf("%s",&gender);
    printf("\n");
    printf("\n");
    printf("\n");
    if (gender =='M' || gender == 'm') standard = height - 100;
       else  standard = height - 110;
    if ( standard == weight) printf("%s Weight Is Standard",name);
       else if (standard > weight) printf("%s Weight Is Under Standard %.2f Kg",name,standard-weight);
       else  printf("%s Weight Is Over Standard %.2f Kg",name,weight-standard);
    getch();
}

โปรแกรมเครื่องคิดเลข

#include
#include
void main() 
{
int num1,num2;
float total;
char mathoperator;
clrscr();
printf("Input First Number         : ");scanf("%d",&num1);
printf("Input Second  Number       : ");scanf("%d",&num2);
printf("Input Operator [+, -, *, /]:  ");scanf("%s",&mathoperator);
  if (mathoperator =='+') total = num1+num2;
else  if (mathoperator =='-') total = num1-num2;
else  if (mathoperator =='*') total = num1*num2;
 else  if (mathoperator =='/') total = num1/num2;
  else
  {
  printf("Wrong Operator\n");
  printf("Press Any Key to Exit\n");
  getch();
  exit();
  }
printf("Output : %d %c %d = %.0f",num1,mathoperator,num2,total);
getch();
}

โปรแกรมรับคะแนนกลางภาค ปลายภาค

#include
#include
void main()
{
int mid,final,sum;
clrscr();
printf("Input Score Midterm = ");scanf("%d",&mid);
printf("Input Score Final   = ");scanf("%d",&final);
    sum = mid + final;
printf("Sum Score           = %d\n",sum);
if (sum >= 80)
{
printf("Grade               = A ");
}
else if (sum >= 70)
{
printf("Grade               = B ");
}
else if (sum >= 60)
{
printf("Grade               = C ");
}
else if (sum >= 50)
{
printf("Grade               = D ");
}
else
{
printf("Grade               = E ");
}
getch();
}