Advertisement
derazanother

compro1Sut

Jan 30th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.38 KB | None | 0 0
  1. //ตัวดำเนินการ2
  2. //ข้อ1
  3. #include<stdio.h>
  4. #include <stdlib.h>
  5. int main(){
  6.     char ch;
  7.     printf("Enter a character: ");
  8.  
  9.         scanf("%c",&ch);
  10.        
  11.  
  12.     printf("Capital letter of '%c' is '%c'.\n ",ch,ch-32);
  13.     printf("ASCII value of '%c' is %d.\n",ch-32,ch-32);
  14.     if(ch%2==0){
  15.          printf("%d is an odd number. \n",ch-32);
  16.     }
  17.    else
  18.    {
  19.         printf("%d is Even number ",ch-32);
  20.    }
  21.    
  22.  return 0;  
  23. }
  24. //_______________________________________________________________
  25. //ข้อ2
  26. #include<stdio.h>
  27. int main(){
  28.     int a,b,c,max,min,x=0;
  29.         printf("Enter Number %d: ",x+1);
  30.             scanf("%d",&a);
  31.         printf("Enter Number %d: ",x+2);
  32.             scanf("%d",&b);
  33.         printf("Enter Number %d: ",x+3);
  34.             scanf("%d",&c);
  35.  
  36.         if(a>b&&a>c){
  37.             max = a;
  38.         }
  39.         else if (b>a&&b>c){
  40.             max = b;
  41.         }
  42.         else {
  43.             max = c;
  44.         }
  45.         if(a<b&&a<c){
  46.             min = a;
  47.         }
  48.         else if (b<a&&b<c){
  49.             min = b;
  50.         }
  51.         else {
  52.             min = c;
  53.         }
  54.     printf("Max = %d ",max);
  55.     printf("Min = %d ",min);
  56.     printf("and %d - %d = %d",max,min,max-min);
  57.     return 0;
  58. }
  59. //___________________________________________________
  60. //ข้อ3
  61. #include<stdio.h>
  62. #include<math.h>  
  63. int main(){
  64.     float a,b,s;
  65.     int x=0;
  66.     printf("Enter Number %d: ",x+1);
  67.             scanf("%f",&a);
  68.         printf("Enter Number %d: ",x+2);
  69.             scanf("%f",&b);
  70.  
  71.             s = a+b;
  72.     printf("%.1f + %.1f = %.1f",a,b,s);
  73.     printf("\nApproximate = %.1f",round(s));
  74.    
  75.     return 0;
  76. }
  77. //__________________________________________
  78. // รับข้อมูล ข้อที่2
  79. #include<stdio.h>
  80. int main(){
  81.         char name[40],id[20],sex;
  82.         int yo;
  83.         float po;
  84.     printf("INPUT...\n");
  85.         printf("Enter name : ");
  86.            scanf("%[^\n]",name);
  87.             fflush(stdin);
  88.         printf("Enter ID: ");
  89.             gets(id);
  90.                 fflush(stdin);
  91.         printf("Enter age: ");
  92.             scanf("%d",&yo);
  93.             fflush(stdin);
  94.         printf("Enter gender: ");
  95.             sex = getchar();
  96.             fflush(stdin);
  97.         printf("Enter score: ");
  98.             scanf("%f",&po);
  99.  
  100.         printf("OUTPUT...\n");    
  101.         printf("1234567890123456789012345678901234567890\n");
  102.         printf("%-15s","NAME :"); puts(name);
  103.         puts("****************************************");
  104.         printf("%-15s","Your ID :"); puts(id);
  105.         puts("****************************************");
  106.         printf("%-10s%-13s%-10s","AGE","Score","Gender");
  107.         puts("\n****************************************");
  108.         printf("%-10d%-13.2f",yo,po); putchar(sex);
  109.     return 0;
  110. }
  111. //__________________________________________________________
  112. //ดำเนินการ 1ข้อ2
  113. #include<stdio.h>
  114. int main(){
  115.     char bo[60];
  116.     int dis;
  117.     float al,pr;
  118.     printf("BOOK: ");
  119.         scanf("%[^\n]",bo);
  120.         fflush(stdin);
  121.  
  122.     printf("PRICE: " );
  123.         scanf("%f",&pr);
  124.         fflush(stdin);
  125.  
  126.     printf("DISCOUNT (%%): ");
  127.         scanf("%d",&dis);
  128.  
  129.     printf("Book and Price = %s %.2f\n",bo,pr);
  130.      al = (pr*dis)/100;
  131.      printf("Discont (20.00%) =  %.2f\n",al);
  132.      printf("Total Price = %.2f\n",pr-al);
  133.     return 0;
  134.    
  135.  
  136. }
  137. //________________________________________________
  138. //ดำเนินการ1 ข้อ3
  139. #include<stdio.h>
  140. int main(){
  141.     int num,a,b,c,x,y,z;
  142.     printf("Enter a number (100-999): ");
  143.         scanf("%d",&num);
  144.  
  145.     a = num/100;
  146.     b = num%100/10;
  147.     c = num%10;
  148.     printf("%d + %d + %d = %d\n",a,b,c,a+b+c);
  149.     x = a+b+c;
  150.     y = x /10 ;
  151.     z = x %10;
  152.      printf("%d + %d = %d\n",y,z,y+z);
  153.     return 0;
  154. }
  155. //___________________________________________
  156. //ดำเนินการ1ข้อ4
  157. #include<stdio.h>
  158. int main(){
  159.     float aok,aot,aonk,fr,sn;
  160.         fr = (1.00*3.00*5.00)/2.00;
  161.         sn = (1.00*7.00*5.00)/2.00;
  162.         aok = fr+sn ;
  163.         aot = (1.00*3.00*2.50)/2.00;
  164.         aonk = aok - aot;
  165.         printf("Area of Kite = %.2f\n",aok);
  166.         printf("Area of Triangle = %.2f\n",aot);
  167.         printf("Area of Non-shade kite  = %.2f\n",aonk);
  168.  
  169.     return 0;
  170. }
  171. //_________________________________________________
  172. //สิ้นสุด
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement