ซาหวัดดีทุกคนนนนนนนน

ขอบคุงมากๆๆๆๆๆๆๆๆๆๆๆๆๆๆๆๆๆ ที่เข้ามาเยี่ยมบล็อกน้า=^ ^=

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

4. ให้เขียนโปรแกรมเพื่อรับจำนวนเงินบาท และบอกว่าใช้ธนบัตรประเภทใดเป็นจำนวนเท่าใด และต้องใช้เหรียญประเภทใด จำนวนเท่าใด

(Filename : bank.cpp)

#include
#include
void main(){int mn;clrscr();
printf("Input total money : ");scanf("%i",&mn);
{ if(mn>=1000) printf("1000 bank :%i",mn/1000);
mn=mn%1000;
}
if(mn>=500){ printf("\n500 bank :%i",mn/500);
mn=mn%500;
}
if(mn>=100){ printf("\n100 bank :%i",mn/100);
mn=mn%100;
}
if(mn>=50){ printf("\n50 bank :%i",mn/50);
mn=mn%50;
}
if(mn>=20){ printf("\n20 bank :%i",mn/20);
mn=mn%20;
}
if(mn>=10){ printf("\n10 coin :%i",mn/10);
mn=mn%10;
}
if(mn>=5){ printf("\n5 coin :%i",mn/5);
mn=mn%5;
}
if(mn>=1){ printf("\n1 coin :%i",mn);
}
getch();
}

3. ให้เขียนโปรแกรมรับตัวอักษรภาษาอังกฤษมาและบอกว่าเป็นสระ หรือ พยัญชนะ

(Filename : eng.cpp)

#include
#include
void main()
{
char az;
clrscr();
printf("Please your input english word A-Z : ");scanf("%c",&az);
switch(az){
case 'a': printf(" a is article"); break;
case 'e': printf(" e is article"); break;
case 'i': printf(" i is article"); break;
case 'o': printf(" o is article"); break;
case 'u': printf(" u is article"); break;
default : printf("%c is consonant",az);
}
getch();
}

2. ให้เขียนโปรแกรม สำหรับคำนวณน้ำหนักมาตรฐาน โดยให้ป้อนข้อมูล ส่วนสูง น้ำหนัก เพศ[M , F]

(Filename : weight.cpp)

#include
#include
void main()
{
char fm;
float h,w;
clrscr();
printf("Your Male(m) or Female(f) : ");scanf("%c",&fm);
printf("\nYour Weight : ");scanf("%f",&w);
printf("\nYour Hight : ");scanf("%f",&h); switch(fm)
switch(fm) {
case 'm': if(h-100==w)
printf("\nYou Standardweight ");
else if(h-100
printf("\nYour weight > Standard : %0.2fkg",w-(h-100));
else if(h-100>w)
printf("\nYour weight Less Than Standard : %0.2fkg",(h-110)-w);
break;
case 'f': if(h-110==w)
printf("\nYou Standard weight ");
else if(h-110
printf("\nYour weight > Standard : %0.2fkg",w-(h-110));
else if(h-110>w)
printf("\nYour weight less Than Standard : %0.2fkg",(h-110)-w);
break;
getch();
}

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();
}

5. ให้เขียนโปรแกรมรับคะแนนกลางภาค ปลายภาค แล้วทำการรวมคะแนนแล้วบอกว่าได้เกรดอะไร

70-79 ได้เกรด B
60-69 ได้เกรด C
50-59 ได้เกรด D
0-49 ได้เกรด E
วิธีทำ

#include
#include
main()
{
clrscr();
int mid,final,score;
printf("Input score midterm : ");
scanf("%i",&mid);
printf("Input score finalterm : ");
scanf("%i",&final);
score=mid+final;
if(score>=80 && score<=100);
printf("Your score is %i nYour grade is A");
if(score>=70 && score <80);
printf("Your score is %i nYour grade is B);
if(score>=60 && score <70);
printf("Your score is %i nYour grade is C);
if(score>=50 && score <60);
printf("Your score is %i nYour grade is D);
elseprintf("Your score is %i nYour grade is E Sorry too.");
getch();
}

4.ให้เขียนโปรแกรมรับตัวเลข 0-100 โดยเปรียบเทียบกับเลข 50 แล้วบอกว่ามากกว่าหรือน้อยกว่า 50

วิธีทำ

#include
#include
main()
{
clrscr();
int number;
printf("Input a number 0-100 : ");
scanf("%i",&number);
if(number<50);
printf("%i is <50",number);
else if(number==50)
printf("%i is =50",number);
elseprintf("%i is >50");
getch();
}

3. ให้เขียนโปรแกรมเพื่อรับตัวเลข 0-100 แล้วบอกว่า มากกว่าหรือน้อยกว่า 50

วิธีทำ

#include
#include
main()
{
clrscr();
int number;
printf("Input a number 0-100 :");
scanf("%i",&number);
if(number<50>);
printf("%i is <50",number);
else printf("%i is >=50",number);
getch();
}