scanf includestdio h int main float point char
- Slides: 24
ตวอยางการใชคำสง scanf #include<stdio. h> int main() { float point; char name[20]; printf ("Enter your name : "); scanf ("%s", name); printf ("Enter your point : "); scanf ("%f", &point); return 0; } ����� �� ����� & ���������� � ������ & ����� 5
ตวอยางการใชคำสง printf และ scanf #include<stdio. h> int main() { char first[20], last[20]; printf ("Enter your name and surname : "); ������� 1 scanf ("%s %s", first, last); ������ printf ("Hi %s %sn. How are you? ", first, last); ������� return 0; ������ } Enter your name and surname : Somsak Jaidee Hi Somsak Jaidee How are you? 6
ตวอยางการใชคำสง printf และ scanf #include<stdio. h> int main() { char name[40]; float gpa; printf ("Enter your name : "); scanf ("%[^n]", name); printf ("Enter your GPA : "); scanf ("%f", &gpa); printf ("Name : %sn", name); printf ("Gpa : %f", gpa); return 0; } 8
4. 2. 3 ตวดำเนนการ Type 1 int Operator +, -, *, / & ตวถกดำเนนการ Type 2 int Result int +, -, *, / float +, -, *, / int float +, -, *, / float int % int Exam 3*3 9 19/2 9 3*3. 0 9. 000000 19/2. 0 9. 500000 3. 0*3 9. 000000 19. 0/2 9. 500000 3. 0*3. 0 9. 000000 19. 0/2. 0 9. 500000 7%4 3 8%4 0 13
ตวอยางคำสงแสดงผล และรบขอมล char ch 1, ch 2; printf ("Enter Character 1 : "); ch 1 = getchar(); printf ("Enter Character 2 : "); ch 2 = getch(); puts ("n**** Output ****"); printf ("Char 1 = %cn. Char 2 = %c", ch 1, ch 2); Enter Character 1 : J Enter Character 2 : **** Output **** Char 1 = J Char 2 = O ��������� �� 22
4. 4 คำถามทายบท 1. จากตวอยางโปรแกรมตอไปน #include <stdio. h> int main() { char name[20]; int age; printf("Enter your name: "); scanf("%s", name); printf("Enter your age "); scanf("%d", age); printf("Your name is : %sn", name); printf(" Your age is : %dn", age); return 0; } เมอ Run แลวจะไดผลอยางไร 23
- Char ch int i scanf c&i
- Sum0
- Int main(int argc, char** argv)
- Mainint
- #includestdio.h
- #includestdio.h int main()
- Int char float
- Int char float
- Char short
- Short 자료형
- Char int float
- Int max(int x int y)
- Interface calculator public int add(int a int b) class test
- Public void drawsquare(int x, int y, int len)
- Divideint
- #include stdio.h int main() int i = 5
- Int main() int num=4
- Revision task eft
- What is free float and total float
- How to calculate slack in project management
- Void main int main
- Const char *s=""
- Auto break case char
- Struct node int i float j
- Struct node int i float j