Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ตัวดำเนินการ2
- //ข้อ1
- #include<stdio.h>
- #include <stdlib.h>
- int main(){
- char ch;
- printf("Enter a character: ");
- scanf("%c",&ch);
- printf("Capital letter of '%c' is '%c'.\n ",ch,ch-32);
- printf("ASCII value of '%c' is %d.\n",ch-32,ch-32);
- if(ch%2==0){
- printf("%d is an odd number. \n",ch-32);
- }
- else
- {
- printf("%d is Even number ",ch-32);
- }
- return 0;
- }
- //_______________________________________________________________
- //ข้อ2
- #include<stdio.h>
- int main(){
- int a,b,c,max,min,x=0;
- printf("Enter Number %d: ",x+1);
- scanf("%d",&a);
- printf("Enter Number %d: ",x+2);
- scanf("%d",&b);
- printf("Enter Number %d: ",x+3);
- scanf("%d",&c);
- if(a>b&&a>c){
- max = a;
- }
- else if (b>a&&b>c){
- max = b;
- }
- else {
- max = c;
- }
- if(a<b&&a<c){
- min = a;
- }
- else if (b<a&&b<c){
- min = b;
- }
- else {
- min = c;
- }
- printf("Max = %d ",max);
- printf("Min = %d ",min);
- printf("and %d - %d = %d",max,min,max-min);
- return 0;
- }
- //___________________________________________________
- //ข้อ3
- #include<stdio.h>
- #include<math.h>
- int main(){
- float a,b,s;
- int x=0;
- printf("Enter Number %d: ",x+1);
- scanf("%f",&a);
- printf("Enter Number %d: ",x+2);
- scanf("%f",&b);
- s = a+b;
- printf("%.1f + %.1f = %.1f",a,b,s);
- printf("\nApproximate = %.1f",round(s));
- return 0;
- }
- //__________________________________________
- // รับข้อมูล ข้อที่2
- #include<stdio.h>
- int main(){
- char name[40],id[20],sex;
- int yo;
- float po;
- printf("INPUT...\n");
- printf("Enter name : ");
- scanf("%[^\n]",name);
- fflush(stdin);
- printf("Enter ID: ");
- gets(id);
- fflush(stdin);
- printf("Enter age: ");
- scanf("%d",&yo);
- fflush(stdin);
- printf("Enter gender: ");
- sex = getchar();
- fflush(stdin);
- printf("Enter score: ");
- scanf("%f",&po);
- printf("OUTPUT...\n");
- printf("1234567890123456789012345678901234567890\n");
- printf("%-15s","NAME :"); puts(name);
- puts("****************************************");
- printf("%-15s","Your ID :"); puts(id);
- puts("****************************************");
- printf("%-10s%-13s%-10s","AGE","Score","Gender");
- puts("\n****************************************");
- printf("%-10d%-13.2f",yo,po); putchar(sex);
- return 0;
- }
- //__________________________________________________________
- //ดำเนินการ 1ข้อ2
- #include<stdio.h>
- int main(){
- char bo[60];
- int dis;
- float al,pr;
- printf("BOOK: ");
- scanf("%[^\n]",bo);
- fflush(stdin);
- printf("PRICE: " );
- scanf("%f",&pr);
- fflush(stdin);
- printf("DISCOUNT (%%): ");
- scanf("%d",&dis);
- printf("Book and Price = %s %.2f\n",bo,pr);
- al = (pr*dis)/100;
- printf("Discont (20.00%) = %.2f\n",al);
- printf("Total Price = %.2f\n",pr-al);
- return 0;
- }
- //________________________________________________
- //ดำเนินการ1 ข้อ3
- #include<stdio.h>
- int main(){
- int num,a,b,c,x,y,z;
- printf("Enter a number (100-999): ");
- scanf("%d",&num);
- a = num/100;
- b = num%100/10;
- c = num%10;
- printf("%d + %d + %d = %d\n",a,b,c,a+b+c);
- x = a+b+c;
- y = x /10 ;
- z = x %10;
- printf("%d + %d = %d\n",y,z,y+z);
- return 0;
- }
- //___________________________________________
- //ดำเนินการ1ข้อ4
- #include<stdio.h>
- int main(){
- float aok,aot,aonk,fr,sn;
- fr = (1.00*3.00*5.00)/2.00;
- sn = (1.00*7.00*5.00)/2.00;
- aok = fr+sn ;
- aot = (1.00*3.00*2.50)/2.00;
- aonk = aok - aot;
- printf("Area of Kite = %.2f\n",aok);
- printf("Area of Triangle = %.2f\n",aot);
- printf("Area of Non-shade kite = %.2f\n",aonk);
- return 0;
- }
- //_________________________________________________
- //สิ้นสุด
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement