วันพฤหัสบดีที่ 28 สิงหาคม พ.ศ. 2557

อาเรย์

อาเรย์ คือ ชุดข้อมูลชนิดเดียวกันหลายๆจำนวน ขนาดของข้อมูลจะมีค่าเท่ากับขนาดของอาเรย์ที่จองไว้ในตอนที่ประกาศตัวแปร
สมมติว่าประกาศ int Arr[5]={1,2,3,4,5};
จะได้ค่าดังนี้

Arr[0]               Arr[1]                 Arr[2]                   Arr[3]             Arr[4]
1
2
3
4
5


การที่จะใช้อาเรย์แต่ละครังเราจะต้องระบุตำแหน่งของอาเรย์
 เช่น Arr[0]=1 ค่าตำแหน่งที่ ของอาเรย์ Arr มีค่าเท่ากับ 1







วันพุธที่ 27 สิงหาคม พ.ศ. 2557

โปรแกรมสูตรคูณ

code โปรแกรม สูตรคูณ
#include<stdio.h>
#include<conio.h>
void main(){
int value;
printf("input multiplication value:");
scanf("%d",&value);
        for(int i=1;i<=12;i++){
                printf("%d x %d\t=%5d\n",value,i,value*i);
        }
getch();
}


ผลการรันโปรแกรม

โปรแกรมสูตรคูณเป็นการเขียนโปรแกรม วนลูปเพียงลูปเดียว หลักการทำงานคือการรับค่าเข้ามา 1 ค่าแล้วทำการวนลูปคูณกับค่า 1-12 แล้วก่อแสดงค่าออกมา

วันอังคารที่ 26 สิงหาคม พ.ศ. 2557

การประกาศตัวแปร

               การเขียนโปรแกรมทุกๆภาษา จำเป็นต้องมีตัวแปรไว้ เพื่อสำหรับการเก็บค่าและจัดการกับค่าดังกล่าวผ่านตัวแปร 

               ชนิดของตัวแปรในภาษาซี
ที่มาของรูป http://www.eng.su.ac.th/ee/618240/variable.html



              ในภาษาซีจะไม่สามารถนำคำสงวนมาตั้งชื่อเป็นตัวแปรได้ คำสงวนในภาษาซี มีดังต่อไปนี้                                                                                                                   

ที่มาของรูป http://www.lks.ac.th/anchalee/c_reserb.htm


ตัวอย่างการประกาศตัวแปร
int i=0;  ประกาศให้ตัวแปร i เป็นจำนวนเต็ม มี่ค่า เริ่มต้นเท่ากับ 0
float area=5.5 ประกาศให้ตัวแปร area เป็นทศนิยม มี่ค่าเริ่มต้นเท่ากับ 5.5
char name[9]="MoomMarm" ประกาศให้ตัวแปร name เก็บค่าข้อความว่า"MoomMarm"  จะต้องประกาศขนาดของตัวแปรให้มีมากกว่าข้อความ 1 ค่า                                                                                                    

วันเสาร์ที่ 11 มกราคม พ.ศ. 2557

สวัสดีชาวโลก

         ในการเริ่มเขียนโปรแกรม ซึ่งที่สำคัญที่สุดก็ Syntax ของภาษา ซึ่งในแต่ละโปรแกรมก็จะมี Syntax ที่แตกต่างกันออกไป ทุกภาษาจะต้องมี Library ซึ่งเราจำเป็นต้องรู้จักและใช้ Library ให้เป็นเพื่อช่วยในการเขียนโปรแกรมให้งายขึ้น 
          สำหรับภาษา C นั้น Library ที่เป็นพื้นฐานก็คือ stdio.h ซึ่งเวลาทีเราจะใช้ Library ต้องพิมพ์  #include <ชื่อ Library>
         ทุกครั้งที่เขียนโปรแกรมในภาษา C จะต้องมี ฟังก์ชัน main ซึ่ง เป็นฟังก์ชันหลัก ในส่วนข้างหน้าของทุกๆฟังก์ชันจะต้องระบุ data type เสมอ
             void คือ data type ที่ไม่ต้องมีการคืนค่าของฟังก์
          int char float คือ data type ที่ต้องมีการคืนค่าของฟังก์ชัน
       
         ตัวอย่างที่ 1 
 #include <stdio.h>
void main(){
       printf("Hello World"); //printf มาจาก Library stdio.h
}
            ผลัพธ์ของโปรแกรมที่ 1
Hello World //จะแสดงคำว่า Hello World ออกมาทางหน้าจอ

    
        ตัวอย่างที่ 2
 #include <stdio.h>
int main(){
       printf("Hello World"); //printf มาจาก Library stdio.h
       return 0;//การคืนค่าของฟังก์ชัน
}
            ผลัพธ์ของโปรแกรม2
Hello World //จะแสดงคำว่า Hello World ออกมาทางหน้าจอซึ่งเหมือนกับโปรแกรมที่1

วันพฤหัสบดีที่ 9 มกราคม พ.ศ. 2557

Intro to C

         To start  programming The most important Syntax of the language, each program will have different Syntax away. And it have a Library,we need to know and use the Library to make it easier.
           For C, the Library at the base is stdio.h which time we will use the Library to type # include <Name Library>.
         Every time you write a program in C to be the main function.  In front function must has datatype.
       void  data type be does not have a return  function.
       int,cha,float data type be return a value function

Example 1
  # include <stdio.h>
void main () {
        printf ("Hello World"); / / printf function from Library stdio.h.
}
Output 1
Hello World / / show "Hello World " on the screen..

Example 2
  # include <stdio.h>
int main () {
        printf ("Hello World"); / / printf function from Library stdio.h.
        return 0 ;/ / the return value of the function.
}
Output 2
Hello World / / show "Hello World " on the screen same Ex1.