Download presentation
Presentation is loading. Please wait.
Published byJason Moore Modified over 9 years ago
1
LAB 3: FORMATTED I/O AND C LIBRARY FUNCTIONS ITS100: Computer and Programming Lab. Section 1 Instructor: Wirat Chinnan TAs: Ms. Sasirassamee Buavirat Mr. Thanasan Tanhermhong (Tum) Ms. Pattheera Panitsuk (Fon+) Mr. Pongsate Tangseng Mr. Chinorot Wangtragulsang Mr. Kanin Assantachai (Ob) 1
2
printf() printf() is for output 2
3
scanf() scanf() is for input. Do not forget & in front of variable names. 3
4
scanf() 4
5
Arithmetic Operator 5
6
Mathematical Functions #include 6 ceil(X) Round X up floor(X) Round X down
7
Mathematical Functions #include 7 ceil(X) Round X up floor(X) Round X down
8
Finds the common log of n+3 of an input. 8 #include int main() { float n, ans; printf(“Enter a number: ”); scanf(“%f”,&n); n = n+3; ans = log10(n); printf(“log10(n+3)= %f\n”, ans); return 0; } Enter a number : 1 log10(n+3)= 0.477121
9
Mathematical Functions #include 9 ceil(X) Round X up floor(X) Round X down
10
Finds the power of an input. 10 #include int main() { int n1,n2, ans; printf(“Enter two numbers: ”); scanf(“%d %d”,&n1,&n2); ans = pow(n1,n2); printf(“n1 power n2 = %d\n”, ans); return 0; } Enter two Numbers: 2 3 n1 power n2 = 8
11
Mathematical Functions #include 11 ceil(X) Round X up floor(X) Round X down
12
Finds the square root of an input. 12 #include int main() { float n1, ans; printf(“Enter a number: ”); scanf(“%f”,&n1); ans = sqrt(n1); printf(“square root = %f\n”, ans); return 0; } Enter a number : 3 square root = 1.732051
13
Mathematical Functions #include 13 ceil(X) Round X up floor(X) Round X down
14
Finds the round down value of an input. 14 #include int main() { float n1, ans; printf(“Enter a number: ”); scanf(“%f”,&n1); ans = ceil(n1); printf(“Round up = %f\n”, ans); return 0; } Enter a number : 3.6345 Round up = 4.000000
15
Mathematical Functions #include 15 ceil(X) Round X up floor(X) Round X down
16
Finds the round down value of an input. 16 #include int main() { float n1, ans; printf(“Enter a number: ”); scanf(“%f”,&n1); ans = floor(n1); printf(“Round down = %f\n”, ans); return 0; } Enter a number : 3.6345 Round down = 3.000000
17
Formatted Output 17
18
Formatted Output 18 #include int main() { float n1; n1 = 1.732051; printf(“n1 = %.2f\n”, n1); return 0; } n1 = 1.73
19
Formatted Output 19 #include int main() { float n1; n1 = 1.732051; printf(“n1 = %.0f\n”, n1); return 0; } n1 = 1
20
To Do in Class Exercise 1, 3, 4, 5, and Self Practice 7 Call your TA when you finished. You may take a break Be ready for the speed test at 15.00 20
21
Exercise 1 21
22
Exercise 3 22
23
Exercise 4 23
24
Exercise 5 24
25
Self Practice 7 25
26
Speed Test Speed test should be treated just like a real exam. Rules: No talking. Be quiet. No mobile phone. No electronic devices other than your PC No Internet No cheating Cheating will result in a severe penalty TAs will not help you (except when your PC crashes). Time allowed: 45 minutes. 26
27
Speed Test Instruction Write your name on the question sheet. Create all workspace on your ‘Desktop’ When you finished Raise your hand to signal the assigned TA TA grades your work Quietly leave the room DO NOT bring the question sheet out. Leave it on your table. 27
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.