วันอาทิตย์ที่ 26 สิงหาคม พ.ศ. 2555

10. Code ตัวอย่างโปรแกรม และหน้าตาโปรแกรมภาษาซี

1.ตัวอย่างโปรแกรมทายปัญหาเชาว์


#include<stdio.h>
int answer;

 main()

{
     printf("Quesion Program\n ");
     printf("'Alice Mother has a five of childs.\n ");
     printf("Name of first one is A,second is B,third is C,fourth is D.'\n ");
     printf("Do you known about a fifth child name?\n ");
     printf("1)ABCD\n ");
     printf("2)E\n ");
     printf("3)Mary\n ");
     printf("4)Alice\n ");
     printf("Choose your answer\n ");
     scanf("%d",&answer);
     switch(answer)
     {
                  case 1 :
                          printf("You're wrong!\n"); 
                          printf("Press any key to continue.."); break;
                  case 2 :
                          printf("You're wrong!\n"); 
                          printf("Press any key to continue.."); break;
                  case 3 :
                          printf("You're wrong!\n");
                          printf("Press any key to continue..");   break;
                  case 4 :
                          printf("you're right!\n");
                          printf("you're who is read them carefully,man.\n");
                           printf("Press any key to continue.."); break;
                 
     }getch();
}
ฝากรูป
2.ตัวอย่างโปรแกรมเลือกการคำนวณทางคณิตศาสตร์ที่ต้องการ
#include<stdio.h>
int type,x,y;

 main()

{
     printf("Program by Sukolpat Siripattaragoon M.5/9 No.7\n ");
     printf("1)Average of two numbers\n ");
     printf("2)Parallelogram area\n ");
     printf("3)Trapezoid area\n ");
     printf("4)exit program\n ");
     printf("Choose your program\n ");
     scanf("%d",&type);
     switch(type)
     {
                  case 1 :
                          printf("Please enter number1:\n");
                          scanf("%d",&x);
                          printf("Please enter number:2\n");
                          scanf("%d",&y);
                          printf("Average total =%d",((x+y)/2)); break;
                  case 2 :
                          printf("Please enter Parallelogram hight:\n");
                          scanf("%d",&x);
                          printf("Please enter Parallelogram bass long:\n");
                          scanf("%d",&y);
                          printf("area total of Parallelogram=%d",(x*y)); break;
                  case 3 :
                          printf("Please enter Trapezoid hight:\n");
                          scanf("%d",&x);
                          printf("Please enter sum of 'parallel line' long\n");
                          scanf("%d",&y);
                          printf("area total of Trapezoid=%d",(x*y/2)); break;
                  case 4 :
                          printf("Exit now\n");
                           printf("Press any key to continue.."); break;
                 
     }getch();
}


ฝากรูป

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

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