Page 4 - รายงานc++
P. 4
การเขียนโปรแกรม c++
ตัวอย่างที่ 1
ี
ี่
ื
ี่
การแสดงอินพุต หรอ อาเรย สิ่งทส าคัญทสุดในการเขยนโปรแกรมคือ Input และ Output ของ
์
้
้
็
้
้
โปรแกรม เพราะว่าทุก ๆ โปรแกรมจาเปนตองติดต่อกับผูใช ในภาษา C++ จะใช Stream เพื่อด าเนินการ
กับ Input และ Output ของโปรแกรม ซึ่ง Stream นั้นเปนไลบรารมาตรฐานของภาษา C++ เราใช ้
็
ี่
้
ั
้
ั
cin stream ส าหรบการ Input และ cout stream ส าหรบ Output และเพื่อใชโดยไม่ตองมี std
prefix
้
็
้
้
์
อาเรย เปนประเภทขอมูลชนิดหนึ่ง ที่คุณสามารถเก็บค่าตัวแปรประเภทเดียวกันไดหลายๆ ค่าไวในตัว
์
้
ี
์
แปรเดียวที่เรยกว่า ตัวแปรอาเรย ในการสรางอาเรยในภาษา C#
#include<stdio.h>
int main()
{
Char * month [] = {“January”, “ February” , “March” , “April” , “May” }
int input;
printf (“\n Enter number 1-5 of Month:”);
scant (“%d , & input);
printf (“\n Month namer is %s \n\n”, mnth[input - 1]);
Enter number 1-5 of
Month: 2
return 0;
Month nam is september
}