1 / 16

Lab 2: C Basics

Lab 2: C Basics. 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).

nerice
Download Presentation

Lab 2: C Basics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lab 2: C Basics ITS100: Computer and Programming Lab. Section 1Instructor: WiratChinnan TAs: Ms. SasirassameeBuavirat Mr. ThanasanTanhermhong (Tum) Ms. PattheeraPanitsuk (Fon+) Mr. PongsateTangseng Mr. ChinorotWangtragulsang Mr. KaninAssantachai (Ob)

  2. variable type printf() and scanf() %c %d %d %ld %f %lf

  3. printf() • printf() is for output

  4. scanf() • scanf() is for input. • Do not forget & in front of variable names.

  5. Float and Integer float d; inti;

  6. #include <stdio.h> int main() { int n1; printf(“Enter a Number: “); scanf(“%d”,&n1); printf(“n1 = %d\n”, n1); return 0; } Print Integer with getting input from keyboard Enter a Number: 10 n1 = 10

  7. #include <stdio.h> int main() { intn1,n2; printf(“Enter 1#: “); scanf(“%d”,&n1); printf(“Enter 2#: “); scanf(“%d”,&n2); printf(“output = %d %d\n”, n1,n2); return 0; } Print Integer with getting input from keyboard Enter 1#: 10 Enter 2#: 20 output = 10 20

  8. Reads in two integer and prints out the result of the first number divided by the second number. #include <stdio.h> int main() { int n1,n2, ans; printf(“Enter two numbers: ”); scanf(“%d %d”,&n1,&n2); ans = n1/n2; // mathematic expression printf(“Remainder = %d\n”, ans); return 0; } Enter two Numbers: 21 6 Remainder = 3

  9. Reads in two decimal and prints out the result of the first number divided by the second number. #include <stdio.h> int main() { float n1,n2, ans; printf(“Enter two numbers: ”); scanf(“%f %f”,&n1,&n2); ans = n1/n2; printf(“Remainder = %f\n”, ans); return 0; } Enter two Numbers: 21 6 Remainder = 3.500000

  10. Reads in two integer and prints out the remainder of the first number divided by the second number. #include <stdio.h> int main() { int n1,n2, ans; printf(“Enter two numbers: ”); scanf(“%d %d”,&n1,&n2); ans = n1%n2; // % means modulo operation printf(“Remainder = %d\n”, ans); return 0; } Enter two Numbers: 22 6 Remainder = 4

  11. Mathematical Functions • #include<math.h> • All of these functions require arguments in float and return float

  12. #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; } Finds the square root of an input. Enter a number : 3 square root = 1.732051

  13. #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; } Finds the power of an input. Enter two Numbers: 2 3 n1 power n2 = 8

  14. To Do in Class • Exercise 1 - 5 • Call your TA when you finished. • You may take a break • Be ready for the speed test at 15.00

  15. 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.

  16. Speed Test Instruction • Write your name on the question sheet. • Create all workspace on your ‘Desktop’ and set workspace’s name follow: Sx_ID_Gx Example : S1_5322793303_G1 (for Section 1 ID 5322793303 Group 1) Example : S1_5322793303_G2 (for Section 1 ID 5322793303 Group 2) • 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.

More Related