lab 3: formatted i/o and c library functions its100: computer and programming lab. section 1...
TRANSCRIPT
1
LAB 3: FORMATTED I/O AND C LIBRARY FUNCTIONSITS100: Computer and Programming Lab.
Section 1Instructor: Wirat Chinnan
TAs:
Ms. Sasirassamee Buavirat
Mr. Thanasan Tanhermhong (Tum)
Ms. Pattheera Panitsuk (Fon+)
Mr. Pongsate Tangseng
Mr. Chinorot Wangtragulsang
Mr. Kanin Assantachai (Ob)
2
printf()• printf() is for output
3
scanf()• scanf() is for input. • Do not forget & in front of variable names.
4
scanf()
5
Arithmetic Operator
6
Mathematical Functions• #include<math.h>
ceil(X) Round X up
floor(X) Round X down
7
Mathematical Functions• #include<math.h>
ceil(X) Round X up
floor(X) Round X down
8
Finds the common log of n+3 of an input.
#include <stdio.h>#include <math.h>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<math.h>
ceil(X) Round X up
floor(X) Round X down
10
Finds the power of an input.
#include <stdio.h>#include <math.h>
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 3n1 power n2 = 8
11
Mathematical Functions• #include<math.h>
ceil(X) Round X up
floor(X) Round X down
12
Finds the square root of an input.
#include <stdio.h>#include <math.h>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 : 3square root = 1.732051
13
Mathematical Functions• #include<math.h>
ceil(X) Round X up
floor(X) Round X down
14
Finds the round down value of an input.
#include <stdio.h>#include <math.h>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.6345Round up = 4.000000
15
Mathematical Functions• #include<math.h>
ceil(X) Round X up
floor(X) Round X down
16
Finds the round down value of an input.
#include <stdio.h>#include <math.h>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.6345Round down = 3.000000
17
Formatted Output
18
Formatted Output
#include <stdio.h>int main(){ float n1; n1 = 1.732051; printf(“n1 = %.2f\n”, n1); return 0;}
n1 = 1.73
19
Formatted Output
#include <stdio.h>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
21
Exercise 1
22
Exercise 3
23
Exercise 4
24
Exercise 5
25
Self Practice 7
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.
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.