More Related Content Similar to 59170284 สาวิกา (20) 59170284 สาวิกา2. void main()
{
printf("Miss.Savika Bucha n
ID:59170284 n Hello GI");
getch();
}#include <stdio.h> : คือกลุ่มฟังก์ชันใช้งานด้าน Input / Output ทั่วๆไป เช่น printf,scanf,puts และคาสั่ง
จัดการไฟล์ เช่น fread,fwrite
void main() : ทาหน้าที่เสมือนกับโปรแกรมหลักที่สั่งให้ชุดคาสั่งทางานรวมถึงการเรียกฟังก์ชันย่อยอื่นๆ
ทางาน
{ } : บอกจุดเริ่มต้นและจุดสิ้นสุดการทางานภายในบล็อกมีเครื่องหมาย { } ย่อยไปได้อีก สิ้นสุดประโยคลง
ท้ายด้วย ; (Semicolon) เสมอ
Printf() : ใช้สาหรับสั่งพิมพ์ข้อมูลทางจอภาพ ข้อมูลดังกล่าวอาจเป็นได้ทั้งข้อความ ค่าคงที่และตัวแปร
getch() : ใช้สาหรับรอรับแป้นคีย์ใดๆหนึ่งตัว โดยข้อมูลที่คีย์เข้าไปจะไม่แสดงผลออกมาทางจอภาพและไม่
ต้องยืนยันด้วยการเคาะปุ่ม Enter
4. run หรือกดแป้นพิมพ์ F11
4. {
int num1,num2,sum;
printf("please insert number1:");
scanf("%d",&num1);
printf("please insert number2:");
scanf("%d",&num2);
sum = num1 + num2;
printf("Sum of %d + %d = %d",num1,num2,sum);
getch();
return 0;
}
6. การคานวณหาพื้นที่ของรูปสี่เหลี่ยม
การหาพื้นที่สี่เหลี่ยม
คางหมูมีสูตรดังนี้ x ผลบวกของด้านคู่ขนาน x สูง
กาหนด w1,w2 = ผลบวกของด้านคู่ขนาน
h = ความสูง
area = พื้นที่ทั้งหมด
0.5×(w1+w2) ×h *1/2=0.5
1.พิมพ์โค้ด
#include <stdio.h>
void main()
{
float w1,w2,h,area;
printf("Please insert side1:");
scanf("%f",&w1);
printf("Please insert side2:");
scanf("%f",&w2);
printf("Please insert height:");
scanf("%f",&h);
area = 0.5 * (w1 + w2) * h;
printf("area of trapezoid side1:%f side2:%f height:%f is area:%f",w1,w2,h,area);
getch();
return 0;
}
10. 1.พิมพ์โค้ด
#include "stdio.h"
void main ()
{
float b,h,area;
printf("please insert Base of triangle:");
scanf("%f",&b);
printf("please insert height of triangle:");
scanf("%f",&h);
area = 0.5 * b * h; printf("Area of triangle base:%f and height:%f area is %.2f",b,h,area);
getch();
return 0;
}
16. Week6_Grade
เป็นการใชฟังก์ชั่น if else
A = (score>=80)
B+ =((score >=75)&&(score <=79))
B =((score >=70)&&(score <=74))
C+ =((score >=65)&&(score <=69))
C =((score >=60)&&(score <=64))
D+ =((score >=55)&&(score <=59))
D =((score >=50)&&(score <=54)) แต่ถ้าได้น้อยกว่า ที่กาหนดให้คือ F
1.พิมพ์โค้ด
#include "stdio.h"
void main()
{
int score;
printf("Please insert your score:");
scanf("%d",&score);
if(score>=80)
printf("You are Grade A");
else if((score >=75)&&(score<=79))
printf("You are Geade B+");
else if((score >=70)&&(score<=74))
printf("You are Geade B");
else if((score >=65)&&(score<=69))
printf("You are Geade C+");
else if((score >=60)&&(score<=64))
printf("You are Geade C");
else if((score >=55)&&(score<=59))
17. printf("You are Geade D+");
else if((score >=50)&&(score<=54))
printf("You are Geade D");
else printf("You are Grade F");
printf("nGoodbye");
getch();
return 0;
}
2. run หรือกดแป้นพิมพ์ F11
24. Week7_sudkoon
1.พิมพ์โค้ด
#include "stdio.h"
void main()
{
int counter,number,counter1; for(counter1=1;counter1<=5;counter1++)
{
printf("Please insert Number:");
scanf("%d",&number);
for(counter=1;counter<=12;counter++)
{
printf("%d x %d =%dn",number,counter,number * counter);
}
}
printf("nGoodBye") ;
getch();
return 0;
}
28. Week8_arrey2D crosstab
1.พิมพ์โค้ด
#include "stdio.h"
void main()
{
int table[9][9],i,j,x;
for(i=1;i<=9;i++)
{
for(j=1;j<=9;j++)
{
x = i-1;
table[x][j- 1]= i*j;
}
}
printf("* |t1t2t3t4t5t6t7t8t9n");
printf("----------------------------------------------- ---------------------------n");
for(i=0;i <9;i++)
{
printf("%d |t",i+1);
for(j=0;j<9;j++)
{
printf("%dt",table[i][j]);
}
}
getch();
return 0;
}