วันจันทร์ที่ 13 สิงหาคม พ.ศ. 2555

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

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


โปรแกรมHello world  
#include<stdio.h>
/* This is my first program. */
main()
{
       clrscr();
       printf("Hello,world \n");
       printf("Press any key to stop \n");
       getch();
} /*end of main*/

 
โค้ดโปรแกรมคำนวณอายุ
#include
main()
{
char name[30];
int birth,current;
printf("Enter name : ");
scanf("%s",name);
printf("Enter Birth of Year : ");
scanf("%d",&birth);
printf("Enter Current Year : ");
scanf("%d",&current);
system("cls");
printf("%s is %d years old.",name,current-birth);
getch();
}

โค้ดโปรแกรมแปลงหน่วยอุณหภูมิ(จากฟาร์เรนไฮต์เป็นเซลเซียส)
#include
main()
{
float F,C;
printf("Enter degree in Farenhite (F) : ");
scanf("%f",&F);
C= (F-32)/1.8;
system("cls");
printf("Degree %.1fF equal %.1fC",F,C);
getch();
}

โปรแกรมหาพื้นที่วงกลม
#include
#define pi 3.14159
main()
{
float radius;
printf("Enter circle radius : ");
scanf("%f",&radius);
system("cls");
printf("Area of circle = %.2f\n", pi*radius*radius);
printf("Circumference of circle = %.2f\n", 2*pi*radius);
getch();
}

credit :  http://concord.exteen.com/20080424/entry-2

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

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