LAB 2: C BASICS ITS100: Computer and Programming Lab. Section 1 Instructor: Wirat Chinnan TAs: Ms. Sasirassamee Buavirat Mr. Thanasan Tanhermhong (Tum)

Slides:



Advertisements
Similar presentations
Computer Programming w/ Eng. Applications
Advertisements

We Have Learned main() { … } Variable –Definition –Calculation –Display We can do some real programming! –Think about your solution design –Express design.
CSC Programming for Science Lecture 5: Actual Programming.
1 CSE1301 Computer Programming Lecture 5 C Primitives 2.
1 CSE1301 Computer Programming Lecture 10: Iteration (Part 1)
The scanf Function The scanf function reads input from the standard input device into one or more variables Example: scanf(“%lf”, &miles); Reads a real.
1 Introduction to Computers and Programming Class 3 Introduction to C Professor Avi Rosenfeld.
1 ICS103 Programming in C Lecture 10: Functions II.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
1 Agenda Variables (Review) Example Input / Output Arithmetic Operations Casting Char as a Number (if time allow)
Basic Input/Output and Variables Ethan Cerami New York
If () else statement, switch statement, while () loop, do…while() loop and for( ; ; ) loop 1.
Lecture No: 16. The scanf() function In C programming language, the scanf() function is used to read information from standard input device (keyboard).
Functions Lecture 4 – Section 2: 9/21/05 Section 4: 9/22/05.
C programming: Variables, Expressions part II. Data Types of Arithmetic Expressions Relational Expressions Logical Expressions Multiple Assignments Compound.
Introduction to Computing Lecture 07: Repetition and Loop Statements (Part II) Introduction to Computing Lecture 07: Repetition and Loop Statements (Part.
Agenda  Commenting  Inputting Data from Keyboard (scanf)  Arithmetic Operators  ( ) * / + - %  Order of Operations  Mixing Different Numeric Data.
1 CSE1301 Computer Programming Lecture 5: Components of a C Program (Part 1) Linda M c Iver.
Lecture-2 Operators and Conditionals. Variables(again???) Type: Representation of “bits” in memory Variables: Name for a memory object. Starts with letters,
Tutorial ICS431 – Introduction to C.
CHAPTER 2 PART #3 INPUT - OUTPUT 1 st semester King Saud University College of Applied studies and Community Service Csc
A First C Program /* Print a Message */ #include main() { printf("This is a test!\n"); } The program is compiled and run as cc pg32.c  a.out  This is.
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
1 C Programming Week 2 Variables, flow control and the Debugger.
LAB 3: FORMATTED I/O AND C LIBRARY FUNCTIONS ITS100: Computer and Programming Lab. Section 1 Instructor: Wirat Chinnan TAs: Ms. Sasirassamee Buavirat Mr.
3. FORMATTED INPUT/OUTPUT. The printf Function The first argument in a call of printf is a string, which may contain both ordinary characters and conversion.
How to design and code functions Chapter 4 (ctd).
1 Programming a Computer Lecture Ten. 2 Outline  A quick introduction to the programming language C  Introduction to software packages: Matlab for numerical.
LAB 2: REPETITION STRUCTURE #2 ITS100: Computer and Programming Lab. Section 1 Instructor: Wirat Chinnan TAs: Ms. Sasirassamee Buavirat Mr. Thanasan Tanhermhong.
Operating System Discussion Section. The Basics of C Reference: Lecture note 2 and 3 notes.html.
Data Types and Conversions, Input from the Keyboard If you can't write it down in English, you can't code it. -- Peter Halpern If you lie to the computer,
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Exercise 1 #include int main() { printf(“Hello C Programming!\n”); return 0; } 1.Run your Visual Studio 2008 or Create a new “project” and add.
Computer Programming for Engineers
IT CS 200: R EPEATATION Lect. Napat Amphaiphan. T HE ABILITY TO DO THE SAME TASK AGAIN BY AGAIN UNTIL THE CONDITION IS MET LOOP 2.
Introduction to Programming Lecture 5: Interaction.
NOTE: C programs consist of functions one of which must be main. C programs consist of functions one of which must be main. Every C program begins executing.
The following statements are for y = -1; if ( x ) if ( x>0 ) y = 1; else y = 0; A. y= -1 x0 B. y= 0 x0 C. y= 1 x
2.3 Output Formatting. Outputting Format Specify the number of spaces, “c”, used to print an integer value with specifier %cd, e.g., %3d, %4d. E.g. printf.
Exercise 2 : Using for loop Repetition (loop) (1)control variable initialization (2)Test Conditon (3)Modification of control variable value order : (1)
Lecture2.
Simple C Programs.
ECE Application Programming
Data Types and Conversions, Input from the Keyboard
Functions, Part 2 of 2 Topics Functions That Return a Value
Chapter 2 Overview of C.
Functions in C Mrs. Chitra M. Gaikwad.
Administrative things
CSI 121 Structure Programming Language Lecture 10: Iteration (Part 1)
Looping.
The while Looping Structure
CSCE 206 Lab Structured Programming in C
The while Looping Structure
Test Next Week Summer 3, 2016 Midterm Exam
Lecture3.
Computer Programming Techniques Semester 1, 1998
EECE.2160 ECE Application Programming
Introduction to Computer Organization & Systems
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
ICS103 Programming in C Lecture 10: Functions II
CSCE 206 Lab Structured Programming in C
The while Looping Structure
DATA TYPES There are four basic data types associated with variables:
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
The while Looping Structure
ICS103 Programming in C Lecture 10: Functions II
EECE.2160 ECE Application Programming
Presentation transcript:

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) 1

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

printf() printf() is for output 3

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

Float and Integer di float d; int i;

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

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

Reads in two integer and prints out the result of the first number divided by the second number. 8 #include 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

Reads in two decimal and prints out the result of the first number divided by the second number. 9 #include 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 =

Reads in two integer and prints out the remainder of the first number divided by the second number. 10 #include 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

Mathematical Functions #include All of these functions require arguments in float and return float 11

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 =

Finds the power of an input. 13 #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

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

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

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_ _G1 (for Section 1 ID Group 1) Example : S1_ _G2 (for Section 1 ID 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. 16