C-Programming. Claude Fuhrer 5 août 2017

Size: px
Start display at page:

Download "C-Programming. Claude Fuhrer 5 août 2017"

Transcription

1 C-Programming Claude Fuhrer 5 août 2017

2 1 Pseudocode The most important step in writing a program, is to understand the problem which should be solved and then establish a strategy to solve it. These two steps are normally independant of the programming language that should be used to write the program. 1.1 A stupid game: guess a number Consider a simple two player game. One player choose a number and keep secret. The second player must guess this number by asking questions to which the first player responds "too big", "too small" or "you found it" We will write two version of this games. In one version, the computer choose the secret number and answer to the questions. In the other version, it must guess the number choosen by its opponent. * 1.2 Version one: computer choose a secret number For this version, to choose the number, the computer use a kind of "virtual dice" called random number generator. Then the computer ask its opponent to guess (that is the opponent enter a value in a given predefined domain, for example between 1 and 100). The computer compare the number entered by the user with the secret number and print the answer. This solution must be a little more formalized to be able to program it. Therefore, one should rewrite it in a slightly modified form: Declare two variables secret and guess Declare a variable found an initalise it to false secret random number between 1 and 100 while found = false do ask the user to enter a guess guess entered number if guess > secret then display text too big end if if guess < secret then display text too small end if if guess = secret then display text You found it found true end if end while 2

3 This pseudocode may now be implemented. For a first introduction one would not use the C programming language, but a visual programming environment where one can draw the program structure. This environment is called blockly 1 Implementing this code into blocky gives something like: 1. Version two: the computer guess the number For the second version of the game, the computer should guess the number choosed by its opponent. For that, one should first understand what could be the strategy to minimise the number of tries. A naive strategy would be enumerates all number in the search domain, one after another. With this strategy, the computer may try up to 100 values before it find the right answer. But it should be possible to reduce this number. Let us show this on a concrete example. If the initial domain is 1 to 100, the computer may gives at first guess the value 50. The opponent answer that this guess is either to big or to small. Imagine that the opponent is too small. The computer has now reduced the search domain between 51 and 100. Applying the same strategy (bissecting the search domain again and again), ensure that, in the general case, the number of tries would be minimal. Let us write this in pseudocode. To simplify the program, one would let the human player answer -1 if the guess is too small, +1 if the guess is too big and 0 if the computer found the right number. 1

4 Define two variables low and high Define a variable guess Define a variable answer Set low 1 Set high 100 repeat guess (high + low) / 2 display guess answer read user answer if answer = -1 low guess end if if answer = 1 high guess end if until answer = 0 2 A very simple program The most simple program used to test almost every programming environment is the famous Hello world. This program just shows the two words hello world on the screen. It would help to understand the basic structure of a C program. The two first lines declare a set of standard function allowing the program to communicates with the user and the operating system. Theses two lines would be used in all of our programs. 1 #include <stdlib.h> 2 #include <stdio.h> Then, a C program has at least one function called main(). The definition of this function may vary with the programming environment and the operating system. The simplest is: 1 int main() 2 { // Some code here 4 return 0; 5 } For C, a pair of curly braces ({}) delimit a block, that is a set of instruction which can be considered as a single complex instruction. 4

5 The sentence (the instruction) return 0; says to the operating system that the program exited without any error. One can see that, in C, every instructions ends with a semicolon! For our Hello world program, the body of the function main() contains a single line to display a message on screen. This would say that the complete program would be: 1 #include <stdlib.h> 2 #include <stdio.h> 6 printf ("Hello world!! \n"); 7 return 0; 8 } The function printf() is used to display a text on screen of your computer (this program does not display windows). A text is delimited with double quotes (") at the beginning and at the end. The character \n says that a new line is appended to the text. At the end of the instruction one can see that it ends with a semicolon. Instruction within a block are always shifted to the right from a fixed quantity of spaces (for example 4 spaces). The would help to enhance the readibility of the program and simplify the search of errors 2.1 Comments To enhance the readbility of a program, one can use comments. Comments are text ignored by the compiler but of a great help for the human programmer. In there is two types of comments, the block comments and the line comment. 1 / * A block comment starts with the two characters slash-star and 2 ends with the tow characted star-slash. It may span over many lines and allows to add useful information to your program. 4 5 Within comments one can write in the language of your choice: 6 auf deutsch, en francais o in italiano. 5

6 7 * / 8 9 // A line comment start with two slashes and end at the end 10 // of the line. If one need a comment over many lines, it 11 // should be repeated 6

7 Variables, base types and operations.1 Variables To store values of computations, one should use variables. The notion of variables within a C program is very similar to the variables used for mathematics. A variable has a name and a type. The name consist of a suite of letters and decimal digits with the following rules: 1. One can use lower cases letters ( a to z ) without accented character or umlaute. 2. One can use upper cases letters ( A to Z ) without accented characters or umlaute. One can use decimal digits ( 0 to 9 ), but not at the beginning of the variable name. That is, the variable name vectord is legal while the name 2nd_value is not. 4. One can use the underscore character ( _ ) to simulates a space between words No other character are allowed. In particular spaces, punctuation and special symbols are not accepted. Moreover, one cannot use as identifier one of the reserved words of C. C is case sensitive, that is, it makes a difference between lower cases and upper cases. For example, the two variables =radius= and =Radius= represent different variables. Normally variables and function names are always written with lower cases. If a variable name consist of two words, one can use either the camel notation meanvalue where the second word is capitalised or the underscore mean_value. The second scheme is recommended for C. Do not be afraid to use long and descriptive variable names. Except where the usage shows immediately the meaning of variable (for example x for the parameter of function), short names are mostly an annoing source of errors. For example 1 area = radius * radius * M_PI; // easy to read and verify 2 k = p * p * K; // what does it mean? Functions names follow the same rules as used for the variables names..2 Signed and unsigned integers The C programming language provides many types for integer and floating points calculations. For signed integers one can use: 7

8 int (2 bits) long int (64 bits) char (8 bits). Signed integers are coded using the two-complement previously seen, that is the range of values represented is always symmetric to zero. For example for the type enumerated above one has: char store values between -128 and int store values between and (that is values between 2 1 and 2 1 1) long int store values between and (that is values between 2 6 and 2 6 1) Moreover, to have unsigned integer, one need to add the reserved word unsigned before. For example: unsigned char store values between 0 and 255 unsigned int store values between 0 and Operators for integer arithmetic. For integer arithmetic, the C programming language provides only the fives operators: + for the addition - for the substraction * for the multiplication / for the integer division (i.e. integer part) % for the modulo, that is the rest of the division...1 Computations with integers All theses operators are infixed that is, they should be used as usual arithmetic operator. One should should be attentive that the result of these standard operation is not always the "expected" result that you learned in math course, due to the domain of definition of the types given above. For example 8

9 1 #include <stdlib.h> 2 #include <stdio.h> 6 char a = 100, b = 6, c; 7 c = a + b; 8 printf ("the sum of a and b is %i\n", c); 9 return 0; 10 } For this example, the program should display: The sum of a and b is 120 Why 120? the sum of these two values should be 16, but, one have seen that the biggest signed integer that one may store on 8 bits (char is stored on 8 bits) is 127. Then (remember the number circle), adding 1 to 127 gives -128, and adding 9 to 127 gives This feature may be disappointing for beginner and also the source of many bugs and error if one do not consider the way computers are "thinking". 1. Exercise Do the same exercise with unsigned char. What is the result of this computation? Where is the limit? What happens if we exceed the limit?.4 Example of calculation using integers: 1 #include <stdio.h> 6 int a, b, c; 7 a = 12; 8 b = 5; 9 c = a + b; 10 printf ("a + b = %i\n", c); c = a - b; 1 printf ("a - b = %i\n", c); c = a * b; 16 printf ("a * b = %i\n", c); c = a / b; 9

10 19 printf ("a / b = %i\n", c); c = a % b; / * % == modulo, i.e. rest of the division * / 22 printf ("a %% b = %i\n", c); 2 24 return 0; 25 }.5 Maximum and minimum value of integers types. The coding used for integers types is the "two-complement", that is, for int the value should be comprised between and This can be easily shown with the following program: 1 #include <stdio.h> 6 int a = 1000; 7 int b = a; 8 printf ("The value of b is %i\n", b); 9 10 b = b * a; 11 printf ("The value of b is %i\n", b); 12 1 b = b * a; 14 printf ("The value of b is %i\n", b); b = b * a; 17 printf ("The value of b is %i\n", b); return 0; 20 } For variables of type unsigned int, the definition domain is 0 to #include <stdio.h> 6 unsigned int a = 1000; 7 unsigned int b = a; 8 printf ("The value of b is %u\n", b); 10

11 9 10 b = b * a; 11 printf ("The value of b is %u\n", b); 12 1 b = b * a; 14 printf ("The value of b is %u\n", b); b = b * a; 17 printf ("The value of b is %u\n", b); return 0; 20 }.6 Floating points The C programming language provides 2 types of floating points numbers. They a both based on the norm IEEE-754. Theses types are: float for floating points simple precision, that is numbers coded onto 2 bits. The definition domain of these numbers is approximately ±10 7 and they provides 6 significant digits. double for floating point double precision, that is numbers coded onto 64 bits..6.1 A simple example of use of floating points numbers 1 #include <stdio.h> 6 float a = 2.5; 7 float b = 0.1; printf ("The value of a is %f and the value of b is %f\n", a, b); 11 printf("the sum a + b is %f\n", a + b); 12 printf("the difference a - b is %f\n", a - b); 1 printf("the product a * b is %f\n", a * b); 14 printf("the quotient a / b is %f\n", a / b); 15 return 0; 16 } To illustrate the limited precision of theses numbers, one can show the following program: 11

12 1 #include <stdio.h> 6 float a = ; 7 float b =.0; 8 float c = a / b; 9 10 printf ("The quotient is : %f\n", c); c = c + 2.0; 1 printf("the new value of c is : %f\n", c); 14 return 0; 15 } If, for the same computing one use variable of type double instead variable of type float, the program gives: 1 #include <stdio.h> 6 double a = ; 7 double b =.0; 8 double c = a / b; 9 10 printf ("The quotient is : %f\n", c); c = c + 0.1; 1 printf("the new value of c is : %f\n", c); 14 return 0; 15 }.6.2 Exercise Compute the perimeter and the area of a circle which radius is given. 1 #include <stdio.h> 12

13 6 float radius, perimeter, area; 7 8 radius = 12.; 9 perimeter = 2.0 *.1415 * radius; 10 area =.1415 * radius * radius; printf ("The perimeter of a circle with radius %f is %f\n", 1 radius, perimeter); 14 printf ("The area of a circle with radius %f is %f\n", 15 radius, area); return 0; 18 }.7 Exercise Write a program to compute the sum of all odd numbers between 1 and #include <stdio.h> 6 int sum; 7 8 sum = ; 9 printf ("The searched sum is : %i\n", sum); 10 return 0; 11 } 1

14 4 Comparisons and boolean operators 4.1 Comparisons operators The C programming language provides boolean and comparisons operators. To compare two numerical values, one can use: < smaller than <= smaller or equal to == equals to >= greater or equal to > greater than These operators may be used to compare numerical values and receive a boolean answer. 4.2 Boolean operators Boolean operators combine boolean values to receive a boolean answer. The boolean operators provided by the C programming language are:! logical not && logical and logical or 14

15 5 Decision and branch 1 #include <stdio.h> 6 int value = 2; 7 8 if (value >= 0) 9 { 10 printf ("value is positive\n"); 11 } 12 else 1 { 14 printf ("value is negative \n"); 15 } 16 return 0; 17 } The use of boolean operators may be: 1 #include <stdio.h> 6 int value = 12; 7 if ( (value >= 0) && (value < 10) ) { 8 printf ("One can write value with only one symbol\n"); 9 } else { 10 printf ("One need at least two symbols to write value\n"); 11 } 12 return 0; 1 } 5.1 Exercise Write a program called stupidgame.c to guess a secret value between 1 and 100. For the first version of this program, the user has only one try before the program quit. 15

16 6 Loops If there is a need to execute an instruction (or a block of consecutive instructions) many times, the program need to to a loop. The C programming language provides many structures for loops. For the beginning, one should only study the while loop. The while loop is defined as follow: while ( <condition> ) { <while block> } The <condition> is a boolean expression which is evaluated either to true of false. If it is evaluated to true, the instructions contained into the <while block> are executed once. Then the program skip to the while condition and evaluate it again. As long as the condition returns true, the loop content is repeated. 6.1 Exercise Write a program to compute the sum of all odd numbers between 1 and #include <stdio.h> 6 int n = 1; 7 int sum =0; 8 9 while (n <= 9999) { 10 sum = sum + n; 11 n = n + 2; 12 } 1 printf ("The searched sum is : %i\n", sum); 14 return 0; 15 } 6.2 Exercise : Collatz conjecture The Collatz conjecture is a problem studied by the mathematician since more than 50 years. The formulation of this conjecture is simple. One choose a natural number n N. Then iteratively, one can compute new value of n using the following rules: if n is even, n n/2 if n is odd, then n n

17 #include <stdio.h> #include <stdlib.h> int main() { int n = 7; printf ("n = %i\n", n); while (n > 1) { if ( (n % 2) == 0) { n = n / 2; } else { n = * n + 1; } printf ("n = %i\n", n); } } / * end while * / return 0; One can slightly modify the program, allowing the user to enter the number to be tested at runtime. For that goal, one should use the function scanf() which allows to read a number from the keyboard. The function scanf() need of format string to define what should be read and the address of a variable to define where the information should be stored. That is, the program modification shoud be: int n; / * Initialisation is no more needed * / printf ("Enter the number to be tested:"); scanf ("%i", &n); printf ("n = %i\n", n); / * already in the previous version * / The format string used here ("%i") says to the system that one should read a value of type int, that is an integer. 6. Exercise : stupid game One should write a two-user game. The first user enter a "secret" number between 1 and 100. The second number should guess this number. If the number entered by the second player is greater than the secret number, the program writes "Too big". If the number entered is smaller than the secret number, the program displays "Too small". The program loops until the second player has found the secret number. 17

18 6.4 Exercise: Von Neumann random number generator The idea of the Von Neumann random generator is very simple. One first choose a four digit number (that is between 1000 and 9999). The this number is squared. The "middle number" of this number is extracted as result of the random number generator and also used for the next step. Let us see that on an example: One choose as first number 124 The square of 124 is The "middle number" can be either 5227 or Let us choose the first version is squared, this gives The "middle number" is 215 This algorithm is very simple to implement but does not provides a "good" list of random number. It is heavingly dependant of the seed (the first number choosed) and has a short sequence. Now you can implement this algorithm as exercise. 1 #include <stdio.h> 6 int number, counter=0; 7 8 printf ("Enter the seed of the sequence (four digit number): "); 9 scanf ("%i", &number); if ( (number < 1000) (number > 9999) ) { 12 printf ("Number outside limit!!\n"); 1 return 0; 14 } while (counter < 10) { 17 / * The number if first squared * / 18 number = number * number; number = number / 100; 21 number = number % 10000; 22 printf ("Next number = %i\n", number); 2 counter++; 24 } 18

19 25 26 return 0; 27 } Try to use this program with the following seeds: 124, 1245, 2, The standard unix random generator The standard unix library (used for C) use a different algorithm, which seems to be better (altough not perfect). 1 static unsigned long next = 1; 2 / * RAND_MAX assumed to be 2767 * / 4 int myrand(void) { 5 next = next * ; 6 return((unsigned)(next/6556) % 2768); 7 } Mersenne Twister A new standard algorithm, called "Mersenne Twister" was developped by Makoto Matsumoto and Takuji Nishimura en This algorithm has a very long period ( ). The numbers produced as uniformely distributed on many dimension. If you need more information, you can read the article on wikipedia (Mersenne Twister) Using the standard random generator for your program. To be able to use the standard random generator into your program, you shoud copy the file diva.h into your computer and modify the search path from Code::blocks. A simple program showing the use of this standard random generator can be: 1 #include <stdio.h> 4 #include "diva.h" 5 6 int main() 7 { 8 int value, counter=0; 9 10 init_random_generator(); while (counter < 10) { 1 value = random_int(121); // 0 <= value <

20 14 15 printf("value is %i\n", value); 16 counter++; 17 } 18 } 20

21 7 Bitwise operations As previously seen, the operators & and allows respectively bitwise and and bitwise or. Theses operations are used to manipulates bits in a word (e.g. an integer value). 7.1 Exercise: Test bits Display all numbers between 1 and 127 where the bit b 4 is set. 7.2 Shift left and shift right To generate mask, one also need the two shift operator: >> shift right << shift left Example of use 1 int x = 0x01 ; / * the value 1 in hexadecimal * / 2 int y = x << ; / * y contains 0x80 * / 4 int z = y >> 1; / * z contains 0x40 * / 7. Exercise: decimal to binary Write a program which ask the user to enter an integer value and then display the binary form of this number. 7.4 The for loop The most used loop in C is the for loop. This loop provides exactly the same functionality as the while, but in a more compact form. For the while loop one has 4 distinct operation to do: 1. declaration of the loop variable 2. initialisation of the loop variable. boolean expression (comparison) to define if the loop should be repeated once again 4. modification of the loop variable. For example: 21

22 1 int i; // Declaration of the loop variable i = 0; // Initialisation 5 while (i < END_VALUE) { // Boolean expression 6... // loop code here 7 8 i= i + 1; // Modification of the loop variable 9 } The for loop writes the last three steps (or all four steps if you a using a compiler implementing the C99 norm) like: 1 int i; 2 for (i = 0; i < END_VALUE; i=i+1) { 4... // loop code here 5 } If your compiler implement the C99 norm, you can even write: 1 for (int i = 0; i < END_VALUE; i=i+1) { 2... // loop code here } The standard configuration of Code::Blocks does not support the C99 norm. It must be added if needed Application of the for loop : trigo functions Let us show a little example of the use of the for loop with the programming of trigo functions. 1. Example 1 : the sine function The sine function of an angle x (given in radians) may be computed using the Taylor serie: sin(x) = x1 1! x! + x5 5! x7 x2n ( 1)n 7! (2n + 1)! +... Unfortunately, using this formulation, the computing of the sine may be difficult to implement in C. Therefore, before one can start to write the program, one first should modify slightly the formula. One can see that the Taylor serie of the sine function is an alternate sum of terms with the form x 2n+1 /(2n + 1)!. Thus, one can write: 22

23 t 1 = x1 1! t = x! = ( 1) t 1 t 5 = x5 5! = ( 1) t t 7 = x7 7! = ( 1) t 5... This array shows us a reccurence relation: x 2 2 x x t 1 = x1 1! = x (1) x 2 t i = ( 1) t i 2 (i 1) i for i and odd (2) sin(x) = t i () i One can then program this schema, using a for loop. Moreover, the number of term that should be computed depends on the desired precision, but also on the type of floating points used. Remember that the type float provide only 6 significant digits. If one need more precision, one can use the type double. 2. Exercise : the arcsin() function The arcsin function is the inverse of the sine function. The Taylor serie defining this function is: arcsin(x) = x x x x (4) 7 Question 1 : How can you rewrite the terms of this serie in a recurrent relationship? Question 2: write a C function that implement your algorithm and test it. What did you remark? 2

24 8 Arrays The notion of array has already be studied within the Matlab course. The idea behind array in C is very similar. Unfortunately, the syntax is different. One can enumerate theses diffences: 1. In C an array must be declared before it can be used. 2. The base type of the array (the type of the cells content) must be defined and cannot be changed.. The size must be defined when array is declared. Once the size is set, it cannot be changed (arrays are not dynamic) 4. The first element of a C array is indexed with value 0 5. The last element has index "size - 1" 6. To access array elements one should use brackets ("[]") and not parenthesis. The following example demonstrate the use of an array in a C program: 1 #include <stdio.h> 6 float array1[5]; // Five cells, base type = float 7 int array2[10]; // Ten cells, base type = int 8 int i; 9 10 array1[0] = 12.2; 11 array1[1] =.1415; 12 array1[2] = 42.12; 1 array1[] = 1.2e7; 14 array1[4] = 12; // Last cell has index size-1 = for (i = 0; i < 10; i=i+1) { // i takes value 0 to 9 17 array2[i] = i * i * i; 18 } for (i = 0; i < 10; i++) { 21 printf ("value of cell %i is %i\n", i, array2[i]); 22 } 2 return 0; 24 } 24

25 8.1 Bubble sort algorithm There is a lot a different sorting algorithms. Here one will study one of the simplest. It is called bubble sort. Let us define a random filled array of integer. For example: The algorithm say that one should compare content of cell of index i with content of cell of index i+1. If the first is smaller than the second, one should swap the content of the two cells. In the example above, the first swap occurs between cell 1 and 2. Which will give: The next swap would be between cells and 4. Afte one pass, one has: The array is not sorted, but, one can see that the biggest value (42) is already at the right place. Moreover, the lightest element has moved for one position left. 25

26 9 Appendix 9.1 C reserved words 9.2 References auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static while 1. The Rosetta code, a web site showing an 26

C: How to Program. Week /Mar/05

C: How to Program. Week /Mar/05 1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

More information

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information Laboratory 2: Programming Basics and Variables Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information 3. Comment: a. name your program with extension.c b. use o option to specify

More information

Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming Chapter 2 - Introduction to C Programming 2 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

More information

DEPARTMENT OF MATHS, MJ COLLEGE

DEPARTMENT OF MATHS, MJ COLLEGE T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,

More information

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are: LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words

More information

A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

More information

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14 C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition

More information

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Introduction to C Programming Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline Printing texts Adding 2 integers Comparing 2 integers C.E.,

More information

Procedures, Parameters, Values and Variables. Steven R. Bagley

Procedures, Parameters, Values and Variables. Steven R. Bagley Procedures, Parameters, Values and Variables Steven R. Bagley Recap A Program is a sequence of statements (instructions) Statements executed one-by-one in order Unless it is changed by the programmer e.g.

More information

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed C Overview C OVERVIEW Goals speed portability allow access to features of the architecture speed C fast executables allows high-level structure without losing access to machine features many popular languages

More information

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure C Overview Basic C Program Structure C OVERVIEW BASIC C PROGRAM STRUCTURE Goals The function main( )is found in every C program and is where every C program begins speed execution portability C uses braces

More information

Chapter 1 & 2 Introduction to C Language

Chapter 1 & 2 Introduction to C Language 1 Chapter 1 & 2 Introduction to C Language Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 1 & 2 - Introduction to C Language 2 Outline 1.1 The History

More information

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

More information

Data Types and Variables in C language

Data Types and Variables in C language Data Types and Variables in C language Basic structure of C programming To write a C program, we first create functions and then put them together. A C program may contain one or more sections. They are

More information

Syntax and Variables

Syntax and Variables Syntax and Variables What the Compiler needs to understand your program, and managing data 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line

More information

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Computer 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 information

Fundamental of Programming (C)

Fundamental 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 information

ANSI C Programming Simple Programs

ANSI C Programming Simple Programs ANSI C Programming Simple Programs /* This program computes the distance between two points */ #include #include #include main() { /* Declare and initialize variables */ double

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered )   FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING ( Word to PDF Converter - Unregistered ) http://www.word-to-pdf-converter.net FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING INTRODUCTION TO C UNIT IV Overview of C Constants, Variables and Data Types

More information

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler

More information

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

More information

Programming and Data Structures

Programming 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 information

EL2310 Scientific Programming

EL2310 Scientific Programming Lecture 7: Introduction to C (pronobis@kth.se) Overview Overview Lecture 7: Introduction to C Wrap Up Basic Datatypes and printf Branching and Loops in C Constant values Wrap Up Lecture 7: Introduction

More information

Lecture 2. Examples of Software. Programming and Data Structure. Programming Languages. Operating Systems. Sudeshna Sarkar

Lecture 2. Examples of Software. Programming and Data Structure. Programming Languages. Operating Systems. Sudeshna Sarkar Examples of Software Programming and Data Structure Lecture 2 Sudeshna Sarkar Read an integer and determine if it is a prime number. A Palindrome recognizer Read in airline route information as a matrix

More information

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING KEY CONCEPTS COMP 10 EXPLORING COMPUTER SCIENCE Lecture 2 Variables, Types, and Programs Problem Definition of task to be performed (by a computer) Algorithm A particular sequence of steps that will solve

More information

Computers Programming Course 7. Iulian Năstac

Computers Programming Course 7. Iulian Năstac Computers Programming Course 7 Iulian Năstac Recap from previous course Operators in C Programming languages typically support a set of operators, which differ in the calling of syntax and/or the argument

More information

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab. University of Technology Laser & Optoelectronics Engineering Department C++ Lab. Second week Variables Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable.

More information

Programming. C++ Basics

Programming. C++ Basics Programming C++ Basics Introduction to C++ C is a programming language developed in the 1970s with the UNIX operating system C programs are efficient and portable across different hardware platforms C++

More information

C Functions. 5.2 Program Modules in C

C Functions. 5.2 Program Modules in C 1 5 C Functions 5.2 Program Modules in C 2 Functions Modules in C Programs combine user-defined functions with library functions - C standard library has a wide variety of functions Function calls Invoking

More information

Introduction to C Final Review Chapters 1-6 & 13

Introduction to C Final Review Chapters 1-6 & 13 Introduction to C Final Review Chapters 1-6 & 13 Variables (Lecture Notes 2) Identifiers You must always define an identifier for a variable Declare and define variables before they are called in an expression

More information

BLM2031 Structured Programming. Zeyneb KURT

BLM2031 Structured Programming. Zeyneb KURT BLM2031 Structured Programming Zeyneb KURT 1 Contact Contact info office : D-219 e-mail zeynebkurt@gmail.com, zeyneb@ce.yildiz.edu.tr When to contact e-mail first, take an appointment What to expect help

More information

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program Syntax What the Compiler needs to understand your program 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line Possibly replacing it with other

More information

Informática Ingeniería en Electrónica y Automática Industrial

Informática Ingeniería en Electrónica y Automática Industrial Informática Ingeniería en Electrónica y Automática Industrial Introduction to C programming language V1.1 Alvaro Perales Eceiza Introduction to C programming language Introduction Main features Functions

More information

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and

More information

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

Unit-II Programming and Problem Solving (BE1/4 CSE-2) Unit-II Programming and Problem Solving (BE1/4 CSE-2) Problem Solving: Algorithm: It is a part of the plan for the computer program. An algorithm is an effective procedure for solving a problem in a finite

More information

Presented By : Gaurav Juneja

Presented By : Gaurav Juneja Presented By : Gaurav Juneja Introduction C is a general purpose language which is very closely associated with UNIX for which it was developed in Bell Laboratories. Most of the programs of UNIX are written

More information

Variables. Data Types.

Variables. Data Types. Variables. Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable. We had to write several lines of code, compile them, and then execute the resulting

More information

ET156 Introduction to C Programming

ET156 Introduction to C Programming ET156 Introduction to C Programming Unit 1 INTRODUCTION TO C PROGRAMMING: THE C COMPILER, VARIABLES, MEMORY, INPUT, AND OUTPUT Instructor : Stan Kong Email : skong@itt tech.edutech.edu Figure 1.3 Components

More information

Fundamentals of Programming

Fundamentals 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 information

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and #include The Use of printf() and scanf() The Use of printf()

More information

Lecture 04 FUNCTIONS AND ARRAYS

Lecture 04 FUNCTIONS AND ARRAYS Lecture 04 FUNCTIONS AND ARRAYS 1 Motivations Divide hug tasks to blocks: divide programs up into sets of cooperating functions. Define new functions with function calls and parameter passing. Use functions

More information

BCA-105 C Language What is C? History of C

BCA-105 C Language What is C? History of C C Language What is C? C is a programming language developed at AT & T s Bell Laboratories of USA in 1972. It was designed and written by a man named Dennis Ritchie. C seems so popular is because it is

More information

ET156 Introduction to C Programming

ET156 Introduction to C Programming ET156 Introduction to C Programming g Unit 22 C Language Elements, Input/output functions, ARITHMETIC EXPRESSIONS AND LIBRARY FUNCTIONS Instructor : Stan Kong Email : skong@itt tech.edutech.edu General

More information

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program

More information

BASIC ELEMENTS OF A COMPUTER PROGRAM

BASIC 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 information

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming

More information

DECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA.

DECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA. DECLARATIONS Character Set, Keywords, Identifiers, Constants, Variables Character Set C uses the uppercase letters A to Z. C uses the lowercase letters a to z. C uses digits 0 to 9. C uses certain Special

More information

printf( Please enter another number: ); scanf( %d, &num2);

printf( Please enter another number: ); scanf( %d, &num2); CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful

More information

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University C Programming Notes Dr. Karne Towson University Reference for C http://www.cplusplus.com/reference/ Main Program #include main() printf( Hello ); Comments: /* comment */ //comment 1 Data Types

More information

Computer Programming : C++

Computer Programming : C++ The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming : C++ Experiment #1 Basics Contents Structure of a program

More information

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are

More information

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g. 1.3a Expressions Expressions An Expression is a sequence of operands and operators that reduces to a single value. An operator is a syntactical token that requires an action be taken An operand is an object

More information

Variables in C. Variables in C. What Are Variables in C? CMSC 104, Fall 2012 John Y. Park

Variables in C. Variables in C. What Are Variables in C? CMSC 104, Fall 2012 John Y. Park Variables in C CMSC 104, Fall 2012 John Y. Park 1 Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement 2 What Are Variables in C? Variables in C have the

More information

CS 61C: Great Ideas in Computer Architecture Introduction to C

CS 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 information

Programming 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 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 information

UEE1302 (1102) F10: Introduction to Computers and Programming

UEE1302 (1102) F10: Introduction to Computers and Programming Computational Intelligence on Automation Lab @ NCTU Learning Objectives UEE1302 (1102) F10: Introduction to Computers and Programming Programming Lecture 00 Programming by Example Introduction to C++ Origins,

More information

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9 Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Uppercase Alphabets Lowercase Alphabets Character Set A, B, C, Y, Z a, b, c, y, z Digits

More information

Chapter 2: Overview of C. Problem Solving & Program Design in C

Chapter 2: Overview of C. Problem Solving & Program Design in C Chapter 2: Overview of C Problem Solving & Program Design in C Addison Wesley is an imprint of Why Learn C? Compact, fast, and powerful High-level Language Standard for program development (wide acceptance)

More information

Introduction to Computing Lecture 01: Introduction to C

Introduction to Computing Lecture 01: Introduction to C Introduction to Computing Lecture 01: Introduction to C Assist.Prof.Dr. Nükhet ÖZBEK Ege University Department of Electrical&Electronics Engineering ozbek.nukhet@gmail.com Topics Introduction to C language

More information

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Fundamental of C Programming Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Q2. Write down the C statement to calculate percentage where three subjects English, hindi, maths

More information

C/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock)

C/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock) C/Java Syntax 1 Lecture 02 Summary Keywords Variable Declarations Data Types Operators Statements if, switch, while, do-while, for Functions 2 By the end of this lecture, you will be able to identify the

More information

C/Java Syntax. Lecture 02 Summary. Keywords Variable Declarations Data Types Operators Statements. Functions. if, switch, while, do-while, for

C/Java Syntax. Lecture 02 Summary. Keywords Variable Declarations Data Types Operators Statements. Functions. if, switch, while, do-while, for C/Java Syntax 1 Lecture 02 Summary Keywords Variable Declarations Data Types Operators Statements if, switch, while, do-while, for Functions 2 1 By the end of this lecture, you will be able to identify

More information

.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar..

.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar.. .. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar.. A Simple Program. simple.c: Basics of C /* CPE 101 Fall 2008 */ /* Alex Dekhtyar */ /* A simple program */ /* This is a comment!

More information

C Language, Token, Keywords, Constant, variable

C Language, Token, Keywords, Constant, variable C Language, Token, Keywords, Constant, variable A language written by Brian Kernighan and Dennis Ritchie. This was to be the language that UNIX was written in to become the first "portable" language. C

More information

Introduction to C An overview of the programming language C, syntax, data types and input/output

Introduction to C An overview of the programming language C, syntax, data types and input/output Introduction to C An overview of the programming language C, syntax, data types and input/output Teil I. a first C program TU Bergakademie Freiberg INMO M. Brändel 2018-10-23 1 PROGRAMMING LANGUAGE C is

More information

Informatica e Sistemi in Tempo Reale

Informatica 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 information

VARIABLES AND CONSTANTS

VARIABLES AND CONSTANTS UNIT 3 Structure VARIABLES AND CONSTANTS Variables and Constants 3.0 Introduction 3.1 Objectives 3.2 Character Set 3.3 Identifiers and Keywords 3.3.1 Rules for Forming Identifiers 3.3.2 Keywords 3.4 Data

More information

Fundamentals of Programming

Fundamentals 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 information

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam Multimedia Programming 2004 Lecture 2 Erwin M. Bakker Joachim Rijsdam Recap Learning C++ by example No groups: everybody should experience developing and programming in C++! Assignments will determine

More information

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010 CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011 Lectures 1-22 Moaaz Siddiq Asad Ali Latest Mcqs MIDTERM EXAMINATION Spring 2010 Question No: 1 ( Marks: 1 ) - Please

More information

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

2/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 information

INTRODUCTION 1 AND REVIEW

INTRODUCTION 1 AND REVIEW INTRODUTION 1 AND REVIEW hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Programming: Advanced Objectives You will learn: Program structure. Program statements. Datatypes. Pointers. Arrays. Structures.

More information

CMPE-013/L. Introduction to C Programming

CMPE-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 information

Lecture 02 Summary. C/Java Syntax 1/14/2009. Keywords Variable Declarations Data Types Operators Statements. Functions

Lecture 02 Summary. C/Java Syntax 1/14/2009. Keywords Variable Declarations Data Types Operators Statements. Functions Lecture 02 Summary C/Java Syntax Keywords Variable Declarations Data Types Operators Statements if, switch, while, do-while, for Functions 1 2 By the end of this lecture, you will be able to identify the

More information

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE a) Mention any 4 characteristic of the object car. Ans name, colour, model number, engine state, power b) What

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture 04 Programs with IO and Loop We will now discuss the module 2,

More information

Creating a C++ Program

Creating a C++ Program Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer. 1 Creating a C++ Program created using an

More information

Lab Session # 1 Introduction to C Language. ALQUDS University Department of Computer Engineering

Lab 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 information

Guide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below:

Guide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below: Q1. Explain the structure of a C program Structure of the C program is shown below: Preprocessor Directives Global Declarations Int main (void) Local Declarations Statements Other functions as required

More information

Computer Programming

Computer Programming Computer Programming Introduction Marius Minea marius@cs.upt.ro http://cs.upt.ro/ marius/curs/cp/ 26 September 2017 Course goals Learn programming fundamentals no prior knowledge needed for those who know,

More information

The C Programming Language Guide for the Robot Course work Module

The C Programming Language Guide for the Robot Course work Module The C Programming Language Guide for the Robot Course work Module Eric Peasley 2018 v6.4 1 2 Table of Contents Variables...5 Assignments...6 Entering Numbers...6 Operators...7 Arithmetic Operators...7

More information

Programming in C++ 4. The lexical basis of C++

Programming in C++ 4. The lexical basis of C++ Programming in C++ 4. The lexical basis of C++! Characters and tokens! Permissible characters! Comments & white spaces! Identifiers! Keywords! Constants! Operators! Summary 1 Characters and tokens A C++

More information

C How to Program, 7/e by Pearson Education, Inc. All Rights Reserved.

C How to Program, 7/e by Pearson Education, Inc. All Rights Reserved. C How to Program, 7/e This chapter serves as an introduction to data structures. Arrays are data structures consisting of related data items of the same type. In Chapter 10, we discuss C s notion of

More information

CS102: Variables and Expressions

CS102: 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 information

VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANGULATHUR

VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANGULATHUR VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANGULATHUR 603 203 FIRST SEMESTER B.E / B.Tech., (Common to all Branches) QUESTION BANK - GE 6151 COMPUTER PROGRAMMING UNIT I - INTRODUCTION Generation and

More information

Chapter 2. C++ Syntax and Semantics, and the Program Development Process. Dale/Weems 1

Chapter 2. C++ Syntax and Semantics, and the Program Development Process. Dale/Weems 1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems 1 Chapter 2 Topics Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables

More information

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple

More information

2. Numbers In, Numbers Out

2. Numbers In, Numbers Out COMP1917: Computing 1 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. COMP1917 15s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write down a proposed solution Break

More information

DETAILED SYLLABUS INTRODUCTION TO C LANGUAGE

DETAILED SYLLABUS INTRODUCTION TO C LANGUAGE COURSE TITLE C LANGUAGE DETAILED SYLLABUS SR.NO NAME OF CHAPTERS & DETAILS HOURS ALLOTTED 1 INTRODUCTION TO C LANGUAGE About C Language Advantages of C Language Disadvantages of C Language A Sample Program

More information

Getting started with C++ (Part 2)

Getting started with C++ (Part 2) Getting started with C++ (Part 2) CS427: Elements of Software Engineering Lecture 2.2 11am, 16 Jan 2012 CS427 Getting started with C++ (Part 2) 1/22 Outline 1 Recall from last week... 2 Recall: Output

More information

Computer System and programming in C

Computer 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 information

UIC. C Programming Primer. Bharathidasan University

UIC. C Programming Primer. Bharathidasan University C Programming Primer UIC C Programming Primer Bharathidasan University Contents Getting Started 02 Basic Concepts. 02 Variables, Data types and Constants...03 Control Statements and Loops 05 Expressions

More information

Maciej Sobieraj. Lecture 1

Maciej Sobieraj. Lecture 1 Maciej Sobieraj Lecture 1 Outline 1. Introduction to computer programming 2. Advanced flow control and data aggregates Your first program First we need to define our expectations for the program. They

More information

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

Computers Programming Course 6. Iulian Năstac

Computers Programming Course 6. Iulian Năstac Computers Programming Course 6 Iulian Năstac Recap from previous course Data types four basic arithmetic type specifiers: char int float double void optional specifiers: signed, unsigned short long 2 Recap

More information

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

COMP322 - Introduction to C++ Lecture 02 - Basics of C++ COMP322 - Introduction to C++ Lecture 02 - Basics of C++ School of Computer Science 16 January 2012 C++ basics - Arithmetic operators Where possible, C++ will automatically convert among the basic types.

More information

6.096 Introduction to C++ January (IAP) 2009

6.096 Introduction to C++ January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

More information

Coding Workshop. Learning to Program with an Arduino. Lecture Notes. Programming Introduction Values Assignment Arithmetic.

Coding Workshop. Learning to Program with an Arduino. Lecture Notes. Programming Introduction Values Assignment Arithmetic. Coding Workshop Learning to Program with an Arduino Lecture Notes Table of Contents Programming ntroduction Values Assignment Arithmetic Control Tests f Blocks For Blocks Functions Arduino Main Functions

More information

Chapter 2: Introduction to C++

Chapter 2: Introduction to C++ Chapter 2: Introduction to C++ Copyright 2010 Pearson Education, Inc. Copyright Publishing as 2010 Pearson Pearson Addison-Wesley Education, Inc. Publishing as Pearson Addison-Wesley 2.1 Parts of a C++

More information