NWEN 241 Systems Programming Exercises (Set 1)
|
|
- Lionel Rich
- 6 years ago
- Views:
Transcription
1 1. A null statement in C programming is valid but also mandatory in some cases, e.g. if (isalpha(c)) /* true = nonzero, false = zero */ ; /* empty is ok, but ; must be there */ else return(printf("you did not enter an alphabetic character\n")); Instead of using the ; character, what other ways can you define a null statement? Give a simple example like the above. if (isalpha(c)) /* true = nonzero, false = zero */ /* empty is ok, but ; or must be there */ else return(printf("you did not enter an alphabetic character\n")); 2. The return value for printf() is incidental to its main purpose of printing output, and it usually not used. The return type of printf() function is int. Write a simple program to determine the value of printf() and infer its meaning. Under ANSI C, printf() function returns the number of characters it printed. If there is an output error, printf() returns a negative value. The following program illustrates the fact: Output One c = 3 int main(void) int c; c = printf("one"); printf ("\nc = %d",c); 3. What is the output of the following program? Explain. int main(void) int i; for(i=5; --i; ) printf("%d",i); 1
2 What is a more descriptive (understandable) way to write the for loop? Output 4321 For loop starts with i equals to 5, then tests the condition of the loop to execute; as part of the test, the variable i is decremented first, making i contain the value of 4. A true outcome can also be represented by a non-zero value, in this case, i being greater than 0. Execution proceeds into the loop (just one statement) to print i. After printing i = 1, it goes back into the control test which first decrements i to 0; and exits the loop. int main(void) int i; for (i=5; i>0; i--) printf( %d,i); 4. What is the output of the following program? Explain, step-by-step how you got the answer. int i=3; for(i--; i<7; i=7) printf("%d",i++); Output: 2 The for loop starts with i equals 3 and gets decremented by 1. The test for i<7 is true, since i is 2, and execution enters the loop to print the value of i. Then, it executes the expression i=7, and tests the condition i<7. That is false, and execution exits the loop. 5. Explain the effect of the following code: int i; while (i = 2) printf ("Examples of even numbers are: %d %d %d\n", i, i+2, i+4); i = 0; 2
3 Where is the source of the problem? Infinite loop that keeps printing Examples of even numbers are: This is because the while-loop condition is an assignment expression instead of to test, i.e. i==2. 6. In the following code to calculate the area of a circle using a function, will it compile properly? If not, how do you solve the problem? Explain your solution. float AreaOfCircle(float); int main(void) float radius, area; float PI = 22/7.0; printf("radius = "); scanf("%f", &radius); area = AreaOfCircle (radius); printf("area = %f\n", area); float AreaOfCircle (float r) return (PI * r * r); /* area equals Pi times radius squared*/ Compilation Error PI is not visible to the function AreaOfCircle Solution: move declaration float PI = 22/7.0; out of main() function. 7. What is the difference between the declaration and definition of a data object or function? You can use the code example in Q6 to explain. A declaration announces the properties of a data object or a function. The main reason for declaring data objects and functions is type checking. If a variable or function is declared and later reference is made to 3
4 it with data objects that do not match the types in the declaration, the compiler will complain. The purpose of the complaint is to catch type errors at compile time rather than waiting until the program is run, when the results can be more fatal. A definition, on the other hand, actually sets aside storage space (in the case of a data object) or indicates the sequence of statements to be carried out (in the case of a function). 8. Which of the following is an incorrect assignment statement? Explain briefly. (a) n = m = 0; (b) value += 10; (c) mysize = x < y? 9 : 11; (d) testval = (x > 5 x < 0); (e) none of the above (e) none of the above All are valid expressions for an assignment statement. 9. When you compile and execute the following codes, what will be the output? Explain. (a) float c= 3.14; printf("%f", c%2); Output Compiler error Explanation The % operator is applied on a variable of type float. The operands of the % opearator cannot be of float or double. This is why it causes a compiler error. (b) int a=5; a=printf("good")+ printf("boy"); 4
5 printf("%d",a); Output GoodBoy7 Explanation printf() function returns the number of characters printed on the screen. Good and Boy will be printed consecutively. The first printf() returns 4 and the second one returns 3. So = 7 is stored in a. When it is printed, 7 would be printed at the end of GoodBoy. (c) char c = 'A'; printf("%c", c + 10); Output K Explanation The chatracter constant A is stored in the variable c. When 10 is added with c, then 10 is added to the ASCII value of A (i.e. 65), the result is 75. As the result is printed with %c, the character equivalent of 75, which is K, is printed on the screen. (d) int x=10,y=15,a,b; a=x++; b=++y; printf("%d%d\n",a,b); Output 1016 Explanation a = x++ is evaluated as a =x then x = x + 1. So the value of a is 10 and the value of x is 11. The statement b= ++y, ++y is incremented before it is assigned to b. Then b = ++y is evaluated as y = y+1 followed by b = y. So the value of b is 16; hence the output. 5
6 10. When you compile and execute the following codes, what will be the output? (a) int x = 3, y = 5, z = 7, w = 9; w += x; printf("w = %d\n", w); w -= y; printf("w = %d\n", w); x *= z; printf("x = %d\n", x); w += x + y - (z -= w); printf("w = %d, z = %d\n", w, z); w += x -= y %= z; printf("w = %d, x = %d, y = %d\n", w, x, y); w *= x / (y += (z += y)); printf("w = %d, y = %d, z = %d\n", w, y, z); w /= 2 + (w %= (x += y - (z -= -w))); printf("w = %d, x = %d, z = %d\n", w, x, z); Output w = 12 w = 7 x = 21 w = 33, z = 0 Floating exception Explanation w = 12: w += x is w = w + x = = 12 Note that after the above assignment, w is 12. w = 7: w =- y is w = w y = 12 5 = 7 Note that after the above assignment, w is 7. x = 21: x *= z is x = x * z = 3 * 7 = 21 Note that after the above assignment, x is 21. w = 33, z = 0: w += x + y - (z -= w) is evaluated as w = w + (x + y - (z -= w)) = (w + ((x + y) - (z = (z w)))) (z = (z w)) evaluates to 0 (z = (7-7)), with z being assigned 0 6
7 Therefore: w = (w + ((x + y) - (z = (z w)))) = (7 + ((21 + 5) - (0))) = 33 Floating exception: w += x -= y %= z is evaluated as (w = (w + (x = (x - (y = (y % z)))))) y % z is evaluated first. Since z is 0, the modulus operator will fail because of the attempt to divide by 0. This causes the exception. (b) int x = 7, y = -7, z = 11, w =- 11, s = 9, t = 10; x += (y -= (z *= (w /= (s %= t)))); printf("x = %d, y = %d, z = %d, w = %d,\ s = %d, t = %d\n", x, y, z, w, s, t); t += s -= w *= z *= y %= x; printf("x = %d, y %d, z = %d, w = %d,\ s = %d, t = %d\n", x, y, z, w, s, t); Output x = 11, y = 4, z = -11, w = -1, s = 9, t = 10 x = 11, y 4, z = -44, w = 44, s = -35, t = -25 Explanation x = 11, y = 4, z = -11, w = -1, s = 9, t = 10: The expression x += (y -= (z *= (w /= (s %= t)))) is evaluated as x = (x + (y = (y -(z = (z * (w = (w / (s = (s % t))))))))) = (7 + (y = (-7 -(z = (11 * (w = (-11 / (s = (9 % 10))))))))) = (7 + (y = (-7 -(z = (11 * (w = (-11 / (s = 9)))))))) = (7 + (y = (-7 -(z = (11 * (w = (-11 / 9))))))) = (7 + (y = (-7 -(z = (11 * (w = -1)))))) = (7 + (y = (-7 -(z = (11 * -1))))) = (7 + (y = (-7 -(z = -11)))) = (7 + (y = ( ))) = (7 + (y = 4)) = (7 + 4) x = 11 x = 11, y 4, z = -44, w = 44, s = -35, t = -25: The expression t += s -= w *= z *= y %= x is evaluated as t += s -= w *= z *= (y = (y % x)) t += s -= w *= (z = (z*(y = (y % x)))) 7
8 t += s -= (w = (w*(z = (z*(y = (y % x)))))) t += (s = (s - (w = (w*(z = (z*(y = (y % x)))))))) t = (t + (s = (s - (w = (w*(z = (z*(y = (y % x))))))))) = (10 + (s = (9 - (w = (-1*(z = (-11*(y = (4 % 11)))))))) = (10 + (s = (9 - (w = (-1*(z = (-11*(y = 4))))))) = (10 + (s = (9 - (w = (-1*(z = (-11*4)))))) = (10 + (s = (9 - (w = (-1*(z = -44)))))) = (10 + (s = (9 - (w = (-1*-44))))) = (10 + (s = (9 - (w = 44)))) = (10 + (s = (9-44))) = (10 + (s = -35)) = ( ) t = -25 8
MA 511: Computer Programming Lecture 2: Partha Sarathi Mandal
MA 511: Computer Programming Lecture 2: http://www.iitg.ernet.in/psm/indexing_ma511/y10/index.html Partha Sarathi Mandal psm@iitg.ernet.ac.in Dept. of Mathematics, IIT Guwahati Semester 1, 2010-11 Largest
More informationComputer System and programming in C
1 Basic Data Types Integral Types Integers are stored in various sizes. They can be signed or unsigned. Example Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign bit. If the sign
More informationThese are reserved words of the C language. For example int, float, if, else, for, while etc.
Tokens in C Keywords These are reserved words of the C language. For example int, float, if, else, for, while etc. Identifiers An Identifier is a sequence of letters and digits, but must start with a letter.
More informationFundamentals of Programming
Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables
More informationUnit 3 Decision making, Looping and Arrays
Unit 3 Decision making, Looping and Arrays Decision Making During programming, we have a number of situations where we may have to change the order of execution of statements based on certain conditions.
More informationLecture 3. More About C
Copyright 1996 David R. Hanson Computer Science 126, Fall 1996 3-1 Lecture 3. More About C Programming languages have their lingo Programming language Types are categories of values int, float, char Constants
More informationStructured programming
Exercises 2 Version 1.0, 22 September, 2016 Table of Contents 1. Simple C program structure................................................... 1 2. C Functions..................................................................
More informationQuestion 2. [5 points] Given the following symbolic constant definition
CS 101, Spring 2012 Mar 20th Exam 2 Name: Question 1. [5 points] Determine which of the following function calls are valid for a function with the prototype: void drawrect(int width, int height); Assume
More informationProgramming and Data Structures
Programming and Data Structures Teacher: Sudeshna Sarkar sudeshna@cse.iitkgp.ernet.in Department of Computer Science and Engineering Indian Institute of Technology Kharagpur #include int main()
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering
More informationCS102: Variables and Expressions
CS102: Variables and Expressions The topic of variables is one of the most important in C or any other high-level programming language. We will start with a simple example: int x; printf("the value of
More informationExpressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators
Expressions 1 Expressions n Variables and constants linked with operators Arithmetic expressions n Uses arithmetic operators n Can evaluate to any value Logical expressions n Uses relational and logical
More informationOperators And Expressions
Operators And Expressions Operators Arithmetic Operators Relational and Logical Operators Special Operators Arithmetic Operators Operator Action Subtraction, also unary minus + Addition * Multiplication
More informationProgramming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan
Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah Lecturer Department of Computer Science & IT University of Balochistan 1 Outline p Introduction p Program development p C language and beginning with
More informationVariables and Operators 2/20/01 Lecture #
Variables and Operators 2/20/01 Lecture #6 16.070 Variables, their characteristics and their uses Operators, their characteristics and their uses Fesq, 2/20/01 1 16.070 Variables Variables enable you to
More informationDay06 A. Young W. Lim Wed. Young W. Lim Day06 A Wed 1 / 26
Day06 A Young W. Lim 2017-09-20 Wed Young W. Lim Day06 A 2017-09-20 Wed 1 / 26 Outline 1 Based on 2 C Program Control Overview for, while, do... while break and continue Relational and Logical Operators
More informationChapter 6. Loops. Iteration Statements. C s iteration statements are used to set up loops.
Chapter 6 Loops 1 Iteration Statements C s iteration statements are used to set up loops. A loop is a statement whose job is to repeatedly execute some other statement (the loop body). In C, every loop
More informationLecture 2: C Programming Basic
ECE342 Introduction to Embedded Systems Lecture 2: C Programming Basic Ying Tang Electrical and Computer Engineering Rowan University 1 Facts about C C was developed in 1972 in order to write the UNIX
More informationITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University
ITC213: STRUCTURED PROGRAMMING Bhaskar Shrestha National College of Computer Studies Tribhuvan University Lecture 08: Control Statements Readings: Chapter 6 Control Statements and Their Types A control
More information3 The L oop Control Structure
3 The L oop Control Structure Loops The while Loop Tips and Traps More Operators The for Loop Nesting of Loops Multiple Initialisations in the for Loop The Odd Loop The break Statement The continue Statement
More informationProgramming for Electrical and Computer Engineers. Loops
Programming for Electrical and Computer Engineers Loops Dr. D. J. Jackson Lecture 6-1 Iteration Statements C s iteration statements are used to set up loops. A loop is a statement whose job is to repeatedly
More informationLecture 6. Statements
Lecture 6 Statements 1 Statements This chapter introduces the various forms of C++ statements for composing programs You will learn about Expressions Composed instructions Decision instructions Loop instructions
More informationWeek 1 Questions Question Options Answer & Explanation A. 10 B. 20 C. 21 D. 11. A. 97 B. 98 C. 99 D. a
Sr. no. Week 1 Questions Question Options Answer & Explanation 1 Find the output: int x=10; int y; y=x++; printf("%d",x); A. 10 B. 20 C. 21 D. 11 Answer: D x++ increments the value to 11. So printf statement
More informationLAB 6: While and do-while Loops
Name: Joe Bloggs LAB 6: While and do-while Loops Exercises 1 while loop /* Program name: lab6ex1.c * Purpose : This program demonstrates use of while loop int num = 0; while( num!= -1 ) printf("please
More informationC-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga
C-Programming CSC209: Software Tools and Systems Programming Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Adapted from Dan Zingaro s 2015 slides. Week 2.0 1 / 19 What
More informationApplied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011
Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011 Autumn 2015 Lecture 3, Simple C programming M. Eriksson (with contributions from A. Maki and
More informationFunction I/O. Function Input and Output. Input through actual parameters. Output through return value. Input/Output through side effects
Function Input and Output Input through actual parameters Output through return value Only one value can be returned Input/Output through side effects printf scanf 2 tj Function Input and Output int main(void){
More informationMA 511: Computer Programming Lecture 3: Partha Sarathi Mandal
MA 511: Computer Programming Lecture 3: http://www.iitg.ernet.in/psm/indexing_ma511/y10/index.html Partha Sarathi Mandal psm@iitg.ernet.ac.in Dept. of Mathematics, IIT Guwahati Semester 1, 2010-11 Last
More informationFunction I/O. Last Updated 10/30/18
Last Updated 10/30/18 Program Structure Includes Function Declarations void main(void){ foo = fun1(a, b); fun2(2, c); if(fun1(c, d)) { } } Function 1 Definition Function 2 Definition 2 tj Function Input
More informationDecision Making and Loops
Decision Making and Loops Goals of this section Continue looking at decision structures - switch control structures -if-else-if control structures Introduce looping -while loop -do-while loop -simple for
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 9 Pointer Department of Computer Engineering 1/46 Outline Defining and using Pointers
More informationSimple Java Reference
Simple Java Reference This document provides a reference to all the Java syntax used in the Computational Methods course. 1 Compiling and running... 2 2 The main() method... 3 3 Primitive variable types...
More information2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants
Data types, variables, constants Outline.1 Introduction. Text.3 Memory Concepts.4 Naming Convention of Variables.5 Arithmetic in C.6 Type Conversion Definition: Computer Program A Computer program is a
More informationFlow Control. CSC215 Lecture
Flow Control CSC215 Lecture Outline Blocks and compound statements Conditional statements if - statement if-else - statement switch - statement? : opertator Nested conditional statements Repetitive statements
More informationDECISION MAKING STATEMENTS
DECISION MAKING STATEMENTS If, else if, switch case These statements allow the execution of selective statements based on certain decision criteria. C language provides the following statements: if statement
More informationProgramming in C++ 5. Integral data types
Programming in C++ 5. Integral data types! Introduction! Type int! Integer multiplication & division! Increment & decrement operators! Associativity & precedence of operators! Some common operators! Long
More informationSubject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100
Code: DC-05 Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 NOTE: There are 11 Questions in all. Question 1 is compulsory and carries 16 marks. Answer to Q. 1. must be written in the space
More informationChapter 4: Basic C Operators
Chapter 4: Basic C Operators In this chapter, you will learn about: Arithmetic operators Unary operators Binary operators Assignment operators Equalities and relational operators Logical operators Conditional
More informationCS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015
CS 141 - Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015 You may take this test with you after the test, but you must turn in your answer sheet. This test has the following sections:
More informationDay05 A. Young W. Lim Sat. Young W. Lim Day05 A Sat 1 / 14
Day05 A Young W. Lim 2017-10-07 Sat Young W. Lim Day05 A 2017-10-07 Sat 1 / 14 Outline 1 Based on 2 Structured Programming (2) Conditions and Loops Conditional Statements Loop Statements Type Cast Young
More informationUnit 7. Functions. Need of User Defined Functions
Unit 7 Functions Functions are the building blocks where every program activity occurs. They are self contained program segments that carry out some specific, well defined task. Every C program must have
More informationUse a calculator and c = 2 π r to calculate the circumference of a circle with a radius of 1.0.
Floating Point Math Submitted by Andy Lindsay on Thu, 03/21/2013-16:37 original source: http://learn.parallax.com/propeller-c-start-simple/floating-point-math Lesson edited to work with Dev-C++ IDE by
More informationFor questions 4 through 7, select the value assigned to the relevant variable, given the declarations: 3) ) This is not allowed
This homework assignment focuses primarily on some of the basic syntax and semantics of C. The answers to the following questions can be determined by consulting a C language reference and/or writing short
More informationEE C Program Elements
EE 1910 C Program Elements Development process need Requirements Specification Program Flow Pseudo Code Code Development Tool Chain Test Executable Code Production 2 tj Requirements Specification Identify
More informationName :. Roll No. :... Invigilator s Signature : INTRODUCTION TO PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70
Name :. Roll No. :..... Invigilator s Signature :.. 2011 INTRODUCTION TO PROGRAMMING Time Allotted : 3 Hours Full Marks : 70 The figures in the margin indicate full marks. Candidates are required to give
More informationLab Session # 1 Introduction to C Language. ALQUDS University Department of Computer Engineering
2013/2014 Programming Fundamentals for Engineers Lab Lab Session # 1 Introduction to C Language ALQUDS University Department of Computer Engineering Objective: Our objective for today s lab session is
More informationC Programming Language. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff
C Programming Language 1 C C is better to use than assembly for embedded systems programming. You can program at a higher level of logic than in assembly, so programs are shorter and easier to understand.
More informationCOMP1917 Computing 1 Written Exam Sample Questions
COMP1917 Computing 1 Written Exam Sample Questions Note: these sample questions are intended to provide examples of a certain style of question which did not occur in the tutorial or laboratory exercises,
More informationUNIVERSITY OF WINDSOR Fall 2007 QUIZ # 2 Solution. Examiner : Ritu Chaturvedi Dated :November 27th, Student Name: Student Number:
UNIVERSITY OF WINDSOR 60-106-01 Fall 2007 QUIZ # 2 Solution Examiner : Ritu Chaturvedi Dated :November 27th, 2007. Student Name: Student Number: INSTRUCTIONS (Please Read Carefully) No calculators allowed.
More information1. The keyword main in C language is used for
1. The keyword main in C language is used for a. an user defined function *b. the first function to be executed in the program c. an user defined variable 2. The role of a C compiler is to translate a.
More informationOperators and expressions. (precedence and associability of operators, type conversions).
Programming I Laboratory - lesson 0 Operators and expressions (precedence and associability of operators, type conversions). An expression is any computation which yields a value. When discussing expressions,
More informationSample Examination. Family Name:... Other Names:... Signature:... Student Number:...
Family Name:... Other Names:... Signature:... Student Number:... THE UNIVERSITY OF NEW SOUTH WALES SCHOOL OF COMPUTER SCIENCE AND ENGINEERING Sample Examination COMP1917 Computing 1 EXAM DURATION: 2 HOURS
More informationChapter 3 Structured Program Development
1 Chapter 3 Structured Program Development Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 3 - Structured Program Development Outline 3.1 Introduction
More informationAMCAT Procedure functions and scope Sample Questions
AMCAT Procedure functions and scope Sample Questions Question 1 A function cannot be defined inside another function A. True B. False Explanation: A function cannot be defined inside the another function,
More informationWill introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators
Operators Overview Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators Operands and Operators Mathematical or logical relationships
More information#include <stdio.h> int main() { char s[] = Hsjodi, *p; for (p = s + 5; p >= s; p--) --*p; puts(s); return 0;
1. Short answer questions: (a) Compare the typical contents of a module s header file to the contents of a module s implementation file. Which of these files defines the interface between a module and
More informationProgramming and Data Structure
Programming and Data Structure Sujoy Ghose Sudeshna Sarkar Jayanta Mukhopadhyay Dept. of Computer Science & Engineering. Indian Institute of Technology Kharagpur Spring Semester 2012 Programming and Data
More informationInformatica e Sistemi in Tempo Reale
Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 5, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction
More informationFundamentals of Programming
Fundamentals of Programming Introduction to the C language Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) The C language
More informationChapter 3. Section 3.10 Type of Expressions and Automatic Conversion. CS 50 Hathairat Rattanasook
Chapter 3 Section 3.10 Type of Expressions and Automatic Conversion CS 50 Hathairat Rattanasook Types of Expressions and Automatic Conversions In C, every expression has an associated type. Operators and
More informationBasic Assignment and Arithmetic Operators
C Programming 1 Basic Assignment and Arithmetic Operators C Programming 2 Assignment Operator = int count ; count = 10 ; The first line declares the variable count. In the second line an assignment operator
More informationCS313D: ADVANCED PROGRAMMING LANGUAGE
CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting
More informationComputer Programming 5th Week loops (do-while, for), Arrays, array operations, C libraries
Computer Programming 5th Week loops (do-while, for), Arrays, array operations, C libraries Hazırlayan Asst. Prof. Dr. Tansu Filik Computer Programming Previously on Bil 200 Low-Level I/O getchar, putchar,
More informationDept. of CSE, IIT KGP
Control Flow: Looping CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Types of Repeated Execution Loop: Group of
More informationFloating-point lab deadline moved until Wednesday Today: characters, strings, scanf Characters, strings, scanf questions clicker questions
Announcements Thursday Extras: CS Commons on Thursdays @ 4:00 pm but none next week No office hours next week Monday or Tuesday Reflections: when to use if/switch statements for/while statements Floating-point
More informationCS 61C: Great Ideas in Computer Architecture Introduction to C
CS 61C: Great Ideas in Computer Architecture Introduction to C Instructors: Vladimir Stojanovic & Nicholas Weaver http://inst.eecs.berkeley.edu/~cs61c/ 1 Agenda C vs. Java vs. Python Quick Start Introduction
More informationIntroduction. C provides two styles of flow control:
Introduction C provides two styles of flow control: Branching Looping Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching constructs: if
More informationLesson 3 Introduction to Programming in C
jgromero@inf.uc3m.es Lesson 3 Introduction to Programming in C Programming Grade in Industrial Technology Engineering This work is licensed under a Creative Commons Reconocimiento-NoComercial-CompartirIgual
More informationData types, variables, constants
Data types, variables, constants Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic in C 2.6 Decision
More informationSECTION II: LANGUAGE BASICS
Chapter 5 SECTION II: LANGUAGE BASICS Operators Chapter 04: Basic Fundamentals demonstrated declaring and initializing variables. This chapter depicts how to do something with them, using operators. Operators
More informationBasic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island
Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Data Types Basic Types Enumerated types The type void Derived types
More informationComputer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary
GATE- 2016-17 Postal Correspondence 1 C-Programming Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts, Analysis
More informationComputational Methods of Scientific Programming Lecture 8. Today s lecture Start C/C++ Basic language features
12.010 Computational Methods of Scientific Programming Lecture 8 Today s lecture Start C/C++ Basic language features C History and Background Origins 1973, Bell Labs Public K&R C The C Programming Language,
More informationREPETITION CONTROL STRUCTURE LOGO
CSC 128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING REPETITION CONTROL STRUCTURE 1 Contents 1 Introduction 2 for loop 3 while loop 4 do while loop 2 Introduction It is used when a statement or a block of
More informationBSM540 Basics of C Language
BSM540 Basics of C Language Chapter 4: Character strings & formatted I/O Prof. Manar Mohaisen Department of EEC Engineering Review of the Precedent Lecture To explain the input/output functions printf()
More informationSFU CMPT Topic: Control Statements
SFU CMPT-212 2008-1 1 Topic: Control Statements SFU CMPT-212 2008-1 Topic: Control Statements Ján Maňuch E-mail: jmanuch@sfu.ca Wednesday 23 rd January, 2008 SFU CMPT-212 2008-1 2 Topic: Control Statements
More informationIntroduction to C Programming
1 2 Introduction to C Programming 2.6 Decision Making: Equality and Relational Operators 2 Executable statements Perform actions (calculations, input/output of data) Perform decisions - May want to print
More informationIntroduction to Programming
Introduction to Programming Lecture 5: Interaction Interaction Produce output Get input values 2 Interaction Produce output Get input values 3 Printing Printing messages printf("this is message \n"); Printing
More informationCS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation
CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;
More informationThe detail of sea.c [1] #include <stdio.h> The preprocessor inserts the header file stdio.h at the point.
Chapter 1. An Overview 1.1 Programming and Preparation Operating systems : A collection of special programs Management of machine resources Text editor and C compiler C codes in text file. Source code
More informationCourse Outline Introduction to C-Programming
ECE3411 Fall 2015 Lecture 1a. Course Outline Introduction to C-Programming Marten van Dijk, Syed Kamran Haider Department of Electrical & Computer Engineering University of Connecticut Email: {vandijk,
More informationAssignment: 1. (Unit-1 Flowchart and Algorithm)
Assignment: 1 (Unit-1 Flowchart and Algorithm) 1. Explain: Flowchart with its symbols. 2. Explain: Types of flowchart with example. 3. Explain: Algorithm with example. 4. Draw a flowchart to find the area
More information80 Minutes CENG 230 MidtermExam :40
80 Minutes CENG 230 MidtermExam 02.12.2014 17:40 There are 40 questions (each 2.5 points) for a total of 100 points. Exam Type: A All questions are multiple choice, no points will be lost for wrong answers.
More informationA Look Back at Arithmetic Operators: the Increment and Decrement
A Look Back at Arithmetic Operators: the Increment and Decrement Spring Semester 2016 Programming and Data Structure 27 Increment (++) and Decrement (--) Both of these are unary operators; they operate
More informationBASIC ELEMENTS OF A COMPUTER PROGRAM
BASIC ELEMENTS OF A COMPUTER PROGRAM CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING LOGO Contents 1 Identifier 2 3 Rules for naming and declaring data variables Basic data types 4 Arithmetic operators
More informationProgramming for Engineers Iteration
Programming for Engineers Iteration ICEN 200 Spring 2018 Prof. Dola Saha 1 Data type conversions Grade average example,-./0 class average = 23450-67 893/0298 Grade and number of students can be integers
More informationIntroduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands
Introduction Operators are the symbols which operates on value or a variable. It tells the compiler to perform certain mathematical or logical manipulations. Can be of following categories: Unary requires
More informationFlow of Control. Selection. if statement. True and False in C False is represented by any zero value. switch
Flow of Control True and False in C Conditional Execution Iteration Nested Code(Nested-ifs, Nested-loops) Jumps 1 True and False in C False is represented by any zero value The int expression having the
More informationSOFTWARE Ph.D. Qualifying Exam Spring Consider the following C program which consists of two function definitions including the main function.
(i) (5 pts.) SOFTWARE Ph.D. Qualifying Exam Spring 2018 Consider the following C program which consists of two function definitions including the main function. #include int g(int z) { int y
More informationLecture 9 - C Functions
ECET 264 C Programming Language with Applications Lecture 9 C Functions Paul I. Lin Professor of Electrical & Computer Engineering Technology http://www.etcs.ipfw.edu/~lin Lecture 9- Prof. Paul I. Lin
More informationLecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18
Assignment Lecture 9 Logical Operations Formatted Print Printf Increment and decrement Read through 3.9, 3.10 Read 4.1. 4.2, 4.3 Go through checkpoint exercise 4.1 Logical Operations - Motivation Logical
More informationDr. R. Z. Khan, Associate Professor, Department of Computer Science
ALIGARH MUSLIM UNIVERSITY Department of Computer Science Course: CSM-102: Programming & Problem Solving Using C Academic Session 2015-2016 UNIT-2: Handout-3 Topic: Control Structures (Selection & Repetition)
More informationCOP 3223 Introduction to Programming with C - Study Union - Spring 2018
COP 3223 Introduction to Programming with C - Study Union - Spring 2018 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................
More informationCMPE-013/L. Introduction to C Programming
CMPE-013/L Introduction to C Programming Bryant Wenborg Mairs Spring 2014 What we will cover in 13/L Embedded C on a microcontroller Specific issues with microcontrollers Peripheral usage Reading documentation
More informationECET 264 C Programming Language with Applications. C Program Control
ECET 264 C Programming Language with Applications Lecture 7 C Program Control Paul I. Lin Professor of Electrical & Computer Engineering Technology http://www.etcs.ipfw.edu/~lin Lecture 7 - Paul I. Lin
More informationCS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code
CS102: Standard I/O Our next topic is standard input and standard output in C. The adjective "standard" when applied to "input" or "output" could be interpreted to mean "default". Typically, standard output
More informationChapter 4. Flow of Control
Chapter 4. Flow of Control Byoung-Tak Zhang TA: Hanock Kwak Biointelligence Laboratory School of Computer Science and Engineering Seoul National Univertisy http://bi.snu.ac.kr Sequential flow of control
More informationAs stated earlier, the declaration
The int data type As stated earlier, the declaration int a; is an instruction to the compiler to reserve a certain amount of memory to hold the values of the variable a. How much memory? Two bytes (usually,
More informationCS2141 Software Development using C/C++ C++ Basics
CS2141 Software Development using C/C++ C++ Basics Integers Basic Types Can be short, long, or just plain int C++ does not define the size of them other than short
More informationFundamentals of Computer Programming Using C
CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar Faculty Name: Ami D. Trivedi Class: FYBCA Subject: US01CBCA01 (Fundamentals of Computer Programming Using C) *UNIT 3 (Structured Programming, Library Functions
More information