There are three steps involved in converting your idea of what is to be done to a working program

Size: px
Start display at page:

Download "There are three steps involved in converting your idea of what is to be done to a working program"

Transcription

1 PROGRAMMING Before we start on a course in Numerical methods and programming we should look at some of the basic aspects of programming. We will learn here, how to convert some of our ideas into a working program and what are the parameters to keep in mind when we design an algorithm. There are many languages like, for example C, Fortran, Pascal etc., that help us to convert an algorithm in to something that a computer can understand. We will focus here only on C programming. By the end of the first part, you should have a working knowledge on how to implement an algorithm. With this in mind we will go through very basic features of C and some of the aspects of C programming that is not immediately relevant to the implementation of the algorithms that are taught later in this course. So, let us start looking at how do we create a C program.there are basically three steps involved in converting your ideas into what is to be done to make it a working program. There are three steps involved in converting your idea of what is to be done to a working program Creating a source code in the form of the text file acceptable to the compiler. Invoking the compiler to process the source code and produce an object file. Linking all the object files and libraries to produce an executable We will look at these parts in some more detail here. The source code is where you express the the whole computation you want to do into a series of instructions. The tradition is to use the C source code with an extension.c For example myfile.c. Some compilers insist on this extension. This is an acsii file that you can create using any one of the editors that you are familiar with. We will look at the detailed structure of this code in a little while. We may have different parts of the code in different files. We then compile them separately or together to form object files. During this operation the compiler checks and convert your source code to a language understandable to the particular processor that is used in the computer. These object files that comes with an extension.o, for example myfile.o, are in binary format. The next step is to link these object files and other libraries and header files etc., to produce an executable. This executable file contains a set of instruction in a language that the processor can understand and is the one which we run on the computer. We will see the use of header files and system libraries in the examples given below. Before proceed let us summarize the steps that takes us to run a program in the form of a flow

2 chart. As we said earlier it is the tradition to write a C program file name ending with the extension.c. Example: Below we give a program that computes the square root of a number and prints it on the screen. Since it is a C program we name it as myfile.c, that is with an extension.c. 1 #include <math.h> 2 #include <stdio.h> 3 main() 4 float x,y; 5 scanf( %f\n,&x); 6 y=sqrt(x); 7 printf("%f\n",y); Before we proceed to the compilation of this program let us take a minute to see what does each of the lines mean?. Lines 1 and 2 are header files. These files contain the math library functions and the input output command functions. We need the math function library to use functions like sqrt, log, power etc. We need the stdio library to use functions like scanf and printf which reads and prints the data from the screen. More on this a little later. The program given above just has a main body. Line 3 is declares the starting on this part. The lines inside the following this are the part of the main program.

3 Line 4 is the declaration of the variables. Again we will see more on the variable types later in this course. In this particular example we declare variables x,y as floating points. Line 5 reads the value of the variable from the screen. Line 6 computes the square root of the variable x and put the value into variable y. Line 7 prints out this value of y. We first compile this code to produce an object code using the command cc c myfile.c or an equivalent command available at your machine. The object file produced by this, myfile.o is then linked with the system math library using the command, cc lm myfile.o o myfile.exe, to produce the executable myfile.exe. (the second term in the command above -lm links the object file to the math library. The file name that comes just after o is the name of the executable). We can combine compile and link into one step as will see in later part of the course. Example: Let us now look at a C program that uses the library and another function. #include <math.h> main() #include <stdio.h> float x,y; ( %f\n,&x) y=sqrt(x); printf("%f\n",y); printit(); printf() printf("the program is Over"); This simple C code adds an additional component to the one we saw earlier, it calls a function printit. As before you can see the include files, or what are called header files. Then we will see the main part of the program. This program is basically computing square root of the variable x and it is printing it out on the screen. Then it is calling some function, which prints out a

4 statement. Here we see on of the main feature of a C program. The main part does some of the calculations and it calls another function. The function we called, named printit, which simply prints the sentence the program is over. can be put it a separate file. Let is call it print.c. We will see that how it can be compiled and how it can be executed. There are two ways to compile this program. To compile these programs we could type cc -c sample.c and cc -c print.c separately. This commands will create sample.o and print.o files. We can create the executable by typing the command. cc sample.o print.o -lm -o a.out In this linking command we have put together the two files and also included the math library file m.a We can now execute the program by typing a.out. You could try variations of these commands and programs to figure out why we need the math.h file and why we need to include -lm in the linker etc. Also try it for different math functions, for example calculating the logarithm or trigonometric functions etc. Another way to compile and generate an executable from this is to simply type cc sample.c print.c -lm -o a.out In this the compilation and linking is put together. Let us try another program to illustrate the use of math library and the compilation and linking procedure. Here is the file sample.c, #include<studio.h> #include<math.h> main( ) float x,y; file *FP; FP = fopen( sample.dat, w ); while(x++<3.0) y = tanh(x); fprintf(fp, %f\n,y); Printinit( ); Fclose(FP);

5 and a file print.c, printinit() printf("the program is over" "\n"); As we discussed above, there are two ways for compiling. cc -c sample.c creates the file called sample.o cc -c print.c creates the file called print.o Now, we put them together and produce an executable. In the process we will link it to the math library using lm and use o to direct the executable to an output myexe. cc sample.o print.o lm -o myexe this will create a file myexe. Now, if we did not use the part of the command after -lm, an executable file a.out will be created by the compilation. We could also do it (creating the executable) in one step with the command cc sample.c print.c lm -o myexe To run the program, we use./myexe. Then it prints on the screen that the program is over. This is what we have asked the function print.c. Actually what does this program do? It is computing the tangent hyperbolic function for a range of values of x. We achieve this using the "while" function. The output is written in a file called "sample.dat". Note the fopen and fprintf functions were called for this purpose. Then it calls the function printinit(). Printinit () just prints out the program is over using the function printf. We will see more examples of the use of these functions as we go along. As we saw above in one command we can do two things, compile and link. We can do compilation alone by invoking -c along with cc. If we won t use c, it will compile and link, that is the default. lm is here for linking to math library. Let us see what happens if we do nnt use -lm in the command, that is we do not Link it to the math library and type only cc sample.c print.c o myexe Does it work? it says that it cannot understand tanh Since, tanh is built into the math library, we need that math library to compile this program. To use mathematical functions, we need to link to math library. For other functions, we might

6 need other libraries. These libraries are stored in different parts of the computer. For example in a Linux platform, these libraries are stored in /users/lib. In general, for different operating systems, the library functions are in different places We were also using header files in the program. Header files are used with #include statements. Try removing header file #include<studio.h> and then try to compile cc sample.c print.c lm -o myexe It says that it cannot understand fopen statement and and *FP declaration etc., FILE, fopen and all the statements are actually put in into the header file called <studio.h>. For simple printf statements, we don t need it. So, we now have a basic idea about how to create a program, compile it and run it. We have seen simple codes with the function and we compile it and run it. The anatomy of a program Let us look at the anatomy of a program once again. It can be summarized as below. Compiler preprocessor commands main function name() variable declaration code sub-function-name (arguments) argument declarations variable declarations code We have some compiler preprocessor commands. This includes various #include files. Then comes the main function. Some name can also be given to the main function. Then, we have the variable declarations used in the main code. Then we have sub-functions. In the previous example, we had the sub functions as a separate files. But you can also include them it into the main code. In this case, in one file, we can have main program of the main function and sub-functions or separately. It is a good idea to have the sub-functions separately. We also compile them n link them separately. It is always safer to do that. For large programs, it is good to have sub functions separately. Sub function has also the same structure like main function. It might have some arguments which would be passed into it. Then comes argument declaration. Then we have some variable declarations which is only private to sub functions only. We will see the examples of these. Before going to the example, let us look at each one these in detail. The standard C compiler has four filters. The first one is known as the preprocessor. This part handles the inclusion of files mentioned using the #include command, definition of constants,

7 macro definition etc. The second filter checks the language statements, generates a symbol table and reports any errors found. The third part generates the code and a fourth filter optimizes the code for better performance The fourth one optimizes the function. It improves the code and modifies the code and so that it runs faster. This is an optional part of the compiler. Then we look at variable declaration. C language require that all variables are declared before they can be used. Here we declare the variable with its class name and the data type. The variable declarations can have the following form, [class] [type] [name][ = initial value]. The "initial value" is not a necessary quantity. For example we can declare the real variable "trial" using "auto float trial" or "auto float trail = 0.0". In the latter we also assign the variable a value "0.0". We will now take a closer look at the class statement. In the statement for declaring the variable "trial" we used "auto float trial". This means we have assigned the [class] as auto. In fact this is the default class and not necessary to be mentioned in the declaration. n auto variable is local to the function within which it is declared. Every time the function is entered we need to assign a value to it before it is used. Auto variable is a default one. If we say float, it is taken it as auto. That is the default variable declarations. Here are more examples. (Sample1.c) #include<studio.h> #include<math.h> main( ) float x,y; while(x++<10.0) y = cube(x); printf( %f %f %f \n, x,pow(x,2),y); Cube(x) float x; float y; y = x*x*x; return (y);

8 Here, the variable is declared as float x,y. This is nothing but auto float x, y. We can add more number of variables to one declaration. When we are using more variables, it is separated by comma. Here we are using two variables. In the C program, all the lines are separated by semi-colon. The variable declared as an auto variable float x,y is only private to the main function unless one passes it to other functions. We can have the same variable declared in another function. For example, float y is declared in the sub function. The y value it takes inside the sub function is different from the other declared outside it. So for the main function to get the result of the computation done in the sub function the value has to be returned. In this program x value takes starting from 0 in steps of one in floating point. (We will discuss more on what is a floating point and how is the floating point and an integer actually stored in the computer etc., a little later. Right now, the floating point is the real number.) The sub function actually computes the cubic value of x, returns the value to the main function and prints it. While executing the program, we get the value of square of x (through the pow function) as well as cube of x.. In the function call y = cube(x), we are passing the variable x to the sub funtion. But we are only passing the value of the variable. In the sub function statement the variable name need not be the same. Even if it is the same it has to be decalred just after the function statement. and If we don t declare the use the float x inside the sub function, we will get the cube of x as zero. That is, auto variable float x is private to the function. External, is another class that is possible. An external variable is global to the program. It should be defined outside the function boundary. A function that uses it should declare it as extern. The first declaration creates the storage and the subsequent declarations does not create storage, but just tells the compiler that the reference to this variable should be resolved by the linker. An example program that uses the real variable as external is given below. sample3.c : # include<math.h> #include<studio.h> float z; /* External variable is common to the whole program and is decalred outside the main function */ main() float x; extern float z; /* The main and sub functions that uses the variable should be declare it as extern */ int i; x = 0.0; for(i=1;i<=3;i++) add( x); printf( %f %f \n,x,z);

9 This is the main program. Here we have declared float z outside the main function. That is z has been declared as an external floating point. We are using extern float z in the main function also. The sub function here that the program calls is add(x). That function is shown below. add(a) float a; extern float z; float y; y = sqrt(a); z = x+y; This function is receiving the variable x passed by the main function as variable a. As we have discussed earlier these variables should be declared next line to the function statement. It is also using the variable z which is declared as extern float z. If it is not declared in the sub function, the function will not know what z is. If the z value changes in the main function then automatically the value changes in the sub function and vice versa. Now, the compilation is done by, cc sample3.c add.c lm o a.out. we are not creating the object file. We just do everything together. Then the program is run. We run it and check what value z takes in the program of add.c if we change it in main. We should add printf statements inside the program add.c to do this. add(x) float x; float y; extern float z; y = sqrt(x); z = x+y; printf ( %f \n,z); Put similar print statements in the main to show that the value of z is changed even though it is not passed through the function call. Then,we could have a static variables. These are special definitions. Static variables are initialized only once by the function. The static data is assigned the initial value only on the first time the function is entered and is not re-initialized every time the function is entered. We will see this here with an example (sample2.c)

10 # include<math.h> #include<studio.h> float z; main() float x; extern float z; int i; x = 0.0; for(i=1;i<=3;i++) add( x); printf( %f %f \n,x,z); add(x) float x; static float y = 0.0; extern float z; y = y+2; z = x+y; We declared the static variable y = 0.0 here. It means that it will initialize the value for y as 0 at first. Then, it won t. If we run the program, we get the results as 2,4,6. First it takes the value 0 and then in every further calls to add it increments by 2. Check what happens when static statement is removed? It would initialize this variable the first time it enters the sub function. Since y is initialized every time the values of z will be 2 every time! Static variables are very useful. In many cases, for example, in the case of random number generator, we have some kind of seed. We pass this see to a random number generator and is returns a random number and updates the see. The next time we call the random number generator it give a new number because the seed is new. This is a case where we don t want the seed to me initialized in every call. We want to get a new random number in every call. So in subsequent calls the seed value should not be initialized, that is it should be treated as static. We have auto variable,static variable and external variables. These are the basic three classes that we have gone through. Going back to our definitions in the variable declaration. We have [class] [type] [name ]=[initial value]. We can put any names here. We have to be careful, the variables in the c language are case-sensitive. We mayor may not put the initial value. Second thing is the type. So far we have used only one or two types, float and int.. Here is the summary or the chart of the various data types.

11 We could have an integer or we could have an floating point or we could have an character. Characters are declared as char and integers are declared as int and floating points as float. There are two different types of integers which we can declare, Long integer and Short integer. In most of the present day compilers the integers declared as int are only Long integers. It means if you have 32 bits, then 2^31 is the largest integer which we can represent. One bit is used for sign. The third one refers the unsigned interger, here can use the extra bit for representing integer without sign. So,it is slightly longer than the long integers. Then, we have floating point. Here again we could have single precision or double precision. When we say float, it is single precision. If we say double, then it is double precision.. Let us look at the program which uses all the data types. Here is the program (sample4.c) #include<studio.h> #include<math.h> main() double x,y ; long int i,,j,k; char letter, chain[ ] = a quick fox\n ; letter = B ; Y = 1.01; i = ; i = 2; printf( \n ) printf( %lf %ld %c %s\n, y, i,letter,chain); printf( \n ); j = 0; while(j++<31) x = y*y ; k = 2*i ;

12 printf( %d,%lf,%ld\n,j,x,i); y = x ; i = k ; Here the variables x and y are declared as a double. (i.e. x and y floating point (double) auto variables.). Then variables i.j.k are declared as long integers. If we are using large numbers, it is advisable to use long int. Long int can also be represented as long. We don t need to write long int. letter is a character and is declared using char. Then we have a character array or the character string, a quick fox which is called chain[ ]. These are the examples of character declarations. You can declare a single letter character or a group of characters as letter. We could have an array or string of characters. Here, letter is defined as B. Letter is the character here when it is assigned to a character B. Usually, the character is assigned within single quotes. Then the integer i, has been assigned a number value two. Then, it is printed out. This program contains many printf statements. This example also demonstrates how do we use printf statements. printf usually prints on the screen. As shown in the previous example, you could also open a file and use a fprinf for printing into a file. If we are going to print out a double precision number, then we use %lf or we could use %e. For long integers, we use %ld. In a C program, if we use wrong format in the printf statements, it will print junk but will not give compilation or run time errors The characters are printed using %c and the strings are printed using %s. Run the program and see what it prints. The program has a loop in which j value increases from 0 to 31. The j value is first assigned to zero and increased by steps of one up to 31. The y value is assigned to 1.01 to start with. It then computes the square of that number and it is assigned to y. Basically, it computes the (1.01) ^2 and the square of (1.01)^2 etc. so we will see how long it will go before goes beyond the capability of the computer. What I want to show you is that this floating points and integers, there is a limit to the size of the numbers which the computer can handle because the computer has a finite precision. When then, the program is compiled and run, it prints the number y, integer i, the letter B and the string a quick fox. Then it enters into the loop and prints the square of x every time. It prints x=1.02.then it squares that and keeps squaring it. Since x has been declared as double precision, we can see that it goes all the way up to j=16. Then the machine cannot handle it anymore. At j=17 th loop, x is printed as infinite. As for as the computer is concerned, it is infinite. Similarly the integer I continues to double as j increments by one. You can see that 2^30 is the largest integer it could print. It cannot do beyond that. Then, it gives junk. In the previous program, we can make a little change. Instead of double x,y, we can change it by float x,y. Now, we see what happens. Again we compile it and run it. Now, we see it could not go beyond j=13. But it went up to 16 last time. So, if we want to use larger numbers and we want more precision it is better to use double.

13 Let is now summarize what we have learned about the structure of a c program. A few word about constants. We see above an example of constant assignment z = 2.0/3.0. Now, z is a floating point. For a mathematician 2/3 = 2.0/3.0; but for a computer 2/3 is zero and 2.0/3.0 is non zero!. In general if we find the ratio of 2 integers, the result is the integer only. If we declare z= 2/3, then we get the value of zero. So, we have to be careful while making constant assignment and remember to write it as z=2.0/3.0 or z=2/3.0 or z=2.0/3.

There are three steps involved in converting your idea of what is to be done to a working program

There are three steps involved in converting your idea of what is to be done to a working program PROGRAMMING Before we start on a course in Numerical methods and programming we should look at some of the basic aspects of programming. We will learn here, how to convert some of our ideas into a working

More information

This course has three parts. Elements of C programming. Arithmatic and Error analysis. Some algorithms and their implementation

This course has three parts. Elements of C programming. Arithmatic and Error analysis. Some algorithms and their implementation This course has three parts Elements of C programming. Arithmatic and Error analysis. Some algorithms and their implementation 2 There are three steps involved in converting your idea of what is to be

More information

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson)

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Lecture 9 Functions Dr M Kasim A Jalil Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Objectives In this chapter, you will learn: To understand how to construct programs modularly

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

2. Numbers In, Numbers Out

2. Numbers In, Numbers Out REGZ9280: Global Education Short Course - Engineering 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. REGZ9280 14s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write

More information

CS16 Exam #1 7/17/ Minutes 100 Points total

CS16 Exam #1 7/17/ Minutes 100 Points total CS16 Exam #1 7/17/2012 75 Minutes 100 Points total Name: 1. (10 pts) Write the definition of a C function that takes two integers `a` and `b` as input parameters. The function returns an integer holding

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

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

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

Functions. Systems Programming Concepts

Functions. Systems Programming Concepts Functions Systems Programming Concepts Functions Simple Function Example Function Prototype and Declaration Math Library Functions Function Definition Header Files Random Number Generator Call by Value

More information

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4 BIL 104E Introduction to Scientific and Engineering Computing Lecture 4 Introduction Divide and Conquer Construct a program from smaller pieces or components These smaller pieces are called modules Functions

More information

Arithmetic Expressions in C

Arithmetic Expressions in C Arithmetic Expressions in C Arithmetic Expressions consist of numeric literals, arithmetic operators, and numeric variables. They simplify to a single value, when evaluated. Here is an example of an arithmetic

More information

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University Lesson #3 Variables, Operators, and Expressions Variables We already know the three main types of variables in C: int, char, and double. There is also the float type which is similar to double with only

More information

6-1 (Function). (Function) !*+!"#!, Function Description Example. natural logarithm of x (base e) rounds x to smallest integer not less than x

6-1 (Function). (Function) !*+!#!, Function Description Example. natural logarithm of x (base e) rounds x to smallest integer not less than x (Function) -1.1 Math Library Function!"#! $%&!'(#) preprocessor directive #include !*+!"#!, Function Description Example sqrt(x) square root of x sqrt(900.0) is 30.0 sqrt(9.0) is 3.0 exp(x) log(x)

More information

The C standard library

The C standard library C introduction The C standard library The C standard library 1 / 12 Contents Do not reinvent the wheel Useful headers Man page The C standard library 2 / 12 The Hitchhiker s Guide to the standard library

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

Functions. Prof. Indranil Sen Gupta. Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur. Introduction

Functions. Prof. Indranil Sen Gupta. Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur. Introduction Functions Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur Programming and Data Structure 1 Function Introduction A self-contained program segment that

More information

LESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long

LESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long LESSON 5 ARITHMETIC DATA PROCESSING The arithmetic data types are the fundamental data types of the C language. They are called "arithmetic" because operations such as addition and multiplication can be

More information

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n)

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n) Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Module 10A Lecture - 20 What is a function?

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

CSE123. Program Design and Modular Programming Functions 1-1

CSE123. Program Design and Modular Programming Functions 1-1 CSE123 Program Design and Modular Programming Functions 1-1 5.1 Introduction A function in C is a small sub-program performs a particular task, supports the concept of modular programming design techniques.

More information

Introduction to C Language

Introduction to C Language Introduction to C Language Instructor: Professor I. Charles Ume ME 6405 Introduction to Mechatronics Fall 2006 Instructor: Professor Charles Ume Introduction to C Language History of C Language In 1972,

More information

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 12, FALL 2012

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 12, FALL 2012 CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 12, FALL 2012 TOPICS TODAY Assembling & Linking Assembly Language Separate Compilation in C Scope and Lifetime LINKING IN ASSEMBLY

More information

sends the formatted data to the standard output stream (stdout) int printf ( format_string, argument_1, argument_2,... ) ;

sends the formatted data to the standard output stream (stdout) int printf ( format_string, argument_1, argument_2,... ) ; INPUT AND OUTPUT IN C Function: printf() library: sends the formatted data to the standard output stream (stdout) int printf ( format_string, argument_1, argument_2,... ) ; format_string it is

More information

COSC 2P91. Introduction Part Deux. Week 1b. Brock University. Brock University (Week 1b) Introduction Part Deux 1 / 14

COSC 2P91. Introduction Part Deux. Week 1b. Brock University. Brock University (Week 1b) Introduction Part Deux 1 / 14 COSC 2P91 Introduction Part Deux Week 1b Brock University Brock University (Week 1b) Introduction Part Deux 1 / 14 Source Files Like most other compiled languages, we ll be dealing with a few different

More information

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR 1 Functions Functions are everywhere in C Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Introduction Function A self-contained program segment that carries

More information

Chapter 5 C Functions

Chapter 5 C Functions Chapter 5 C Functions Objectives of this chapter: To construct programs from small pieces called functions. Common math functions in math.h the C Standard Library. sin( ), cos( ), tan( ), atan( ), sqrt(

More information

Functions. Angela Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan.

Functions. Angela Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan. Functions Angela Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2009 Fall Outline 5.1 Introduction 5.3 Math Library Functions 5.4 Functions 5.5

More information

Lecture 3. Review. CS 141 Lecture 3 By Ziad Kobti -Control Structures Examples -Built-in functions. Conditions: Loops: if( ) / else switch

Lecture 3. Review. CS 141 Lecture 3 By Ziad Kobti -Control Structures Examples -Built-in functions. Conditions: Loops: if( ) / else switch Lecture 3 CS 141 Lecture 3 By Ziad Kobti -Control Structures Examples -Built-in functions Review Conditions: if( ) / else switch Loops: for( ) do...while( ) while( )... 1 Examples Display the first 10

More information

C introduction: part 1

C introduction: part 1 What is C? C is a compiled language that gives the programmer maximum control and efficiency 1. 1 https://computer.howstuffworks.com/c1.htm 2 / 26 3 / 26 Outline Basic file structure Main function Compilation

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

Computer Science & Engineering 150A Problem Solving Using Computers

Computer Science & Engineering 150A Problem Solving Using Computers Computer Science & Engineering 150A Problem Solving Using Computers Lecture 03 - Stephen Scott (Adapted from Christopher M. Bourke) 1 / 41 Fall 2009 Chapter 3 3.1 Building Programs from Existing Information

More information

CS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code

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

Functions. Computer System and programming in C Prentice Hall, Inc. All rights reserved.

Functions. Computer System and programming in C Prentice Hall, Inc. All rights reserved. Functions In general, functions are blocks of code that perform a number of pre-defined commands to accomplish something productive. You can either use the built-in library functions or you can create

More information

Computer Science & Engineering 150A Problem Solving Using Computers. Chapter 3. Existing Information. Notes. Notes. Notes. Lecture 03 - Functions

Computer Science & Engineering 150A Problem Solving Using Computers. Chapter 3. Existing Information. Notes. Notes. Notes. Lecture 03 - Functions Computer Science & Engineering 150A Problem Solving Using Computers Lecture 03 - Functions Stephen Scott (Adapted from Christopher M. Bourke) Fall 2009 1 / 1 cbourke@cse.unl.edu Chapter 3 3.1 Building

More information

Programming Fundamentals for Engineers Functions. Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. Modular programming.

Programming Fundamentals for Engineers Functions. Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. Modular programming. Programming Fundamentals for Engineers - 0702113 7. Functions Muntaser Abulafi Yacoub Sabatin Omar Qaraeen 1 Modular programming Your program main() function Calls AnotherFunction1() Returns the results

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

Computers in Engineering. Moving From Fortran to C Michael A. Hawker

Computers in Engineering. Moving From Fortran to C Michael A. Hawker Computers in Engineering COMP 208 Moving From Fortran to C Michael A. Hawker Remember our first Fortran program? PROGRAM hello IMPLICIT NONE!This is my first program WRITE (*,*) "Hello, World!" END PROGRAM

More information

Programming for Engineers Introduction to C

Programming for Engineers Introduction to C Programming for Engineers Introduction to C ICEN 200 Spring 2018 Prof. Dola Saha 1 Simple Program 2 Comments // Fig. 2.1: fig02_01.c // A first program in C begin with //, indicating that these two lines

More information

Learning to Program with Haiku

Learning to Program with Haiku Learning to Program with Haiku Lesson 3 Written by DarkWyrm All material 2010 DarkWyrm So far we've been learning about programming basics, such as how to write a function and how to start looking for

More information

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3). cs3157: another C lecture (mon-21-feb-2005) C pre-processor (1). today: C pre-processor command-line arguments more on data types and operators: booleans in C logical and bitwise operators type conversion

More information

Programming in C Quick Start! Biostatistics 615 Lecture 4

Programming in C Quick Start! Biostatistics 615 Lecture 4 Programming in C Quick Start! Biostatistics 615 Lecture 4 Last Lecture Analysis of Algorithms Empirical Analysis Mathematical Analysis Big-Oh notation Today Basics of programming in C Syntax of C programs

More information

Midterm Exam 2 Solutions C Programming Dr. Beeson, Spring 2009

Midterm Exam 2 Solutions C Programming Dr. Beeson, Spring 2009 Midterm Exam 2 Solutions C Programming Dr. Beeson, Spring 2009 April 16, 2009 Instructions: Please write your answers on the printed exam. Do not turn in any extra pages. No interactive electronic devices

More information

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I BASIC COMPUTATION x public static void main(string [] args) Fundamentals of Computer Science I Outline Using Eclipse Data Types Variables Primitive and Class Data Types Expressions Declaration Assignment

More information

Function Example. Function Definition. C Programming. Syntax. A small program(subroutine) that performs a particular task. Modular programming design

Function Example. Function Definition. C Programming. Syntax. A small program(subroutine) that performs a particular task. Modular programming design What is a Function? C Programming Lecture 8-1 : Function (Basic) A small program(subroutine) that performs a particular task Input : parameter / argument Perform what? : function body Output t : return

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

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

CpSc 1111 Lab 6 Conditional Statements, Loops, the Math Library, and Random Numbers What s the Point?

CpSc 1111 Lab 6 Conditional Statements, Loops, the Math Library, and Random Numbers What s the Point? CpSc 1111 Lab 6 Conditional Statements, Loops, the Math Library, and Random Numbers What s the Point? Overview For this lab, you will use: one or more of the conditional statements explained below scanf()

More information

CS3157: Advanced Programming. Outline

CS3157: Advanced Programming. Outline CS3157: Advanced Programming Lecture #8 Feb 27 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline More c Preprocessor Bitwise operations Character handling Math/random Review for midterm Reading: k&r ch

More information

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU CSE101-lec#12 Designing Structured Programs Introduction to Functions Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU Outline Designing structured programs in C: Counter-controlled repetition

More information

Functions. Autumn Semester 2009 Programming and Data Structure 1. Courtsey: University of Pittsburgh-CSD-Khalifa

Functions. Autumn Semester 2009 Programming and Data Structure 1. Courtsey: University of Pittsburgh-CSD-Khalifa Functions Autumn Semester 2009 Programming and Data Structure 1 Courtsey: University of Pittsburgh-CSD-Khalifa Introduction Function A self-contained program segment that carries out some specific, well-defined

More information

Tutorial No. 2 - Solution (Overview of C)

Tutorial No. 2 - Solution (Overview of C) Tutorial No. 2 - Solution (Overview of C) Computer Programming and Utilization (2110003) 1. Explain the C program development life cycle using flowchart in detail. OR Explain the process of compiling and

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

VARIABLES Storing numbers:

VARIABLES Storing numbers: VARIABLES Storing numbers: You may create and use variables in Matlab to store data. There are a few rules on naming variables though: (1) Variables must begin with a letter and can be followed with any

More information

Chapter 4: Basic C Operators

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

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

More information

6.001 Notes: Section 6.1

6.001 Notes: Section 6.1 6.001 Notes: Section 6.1 Slide 6.1.1 When we first starting talking about Scheme expressions, you may recall we said that (almost) every Scheme expression had three components, a syntax (legal ways of

More information

CpSc 1011 Lab 4 Formatting and Flow Control Windchill Temps

CpSc 1011 Lab 4 Formatting and Flow Control Windchill Temps CpSc 1011 Lab 4 Formatting and Flow Control Windchill Temps Overview By the end of the lab, you will be able to: use fscanf() to accept inputs from the user and use fprint() for print statements to the

More information

(T) x. Casts. A cast converts the value held in variable x to type T

(T) x. Casts. A cast converts the value held in variable x to type T Several New Things 2 s complement representation of negative integers The data size flag in the conversion specification of printf Recast of &n to unsigned long to get the address 2 3 Casts (T) x A cast

More information

CSCI 171 Chapter Outlines

CSCI 171 Chapter Outlines Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures

More information

H192 Midterm 1 Review. Tom Zajdel

H192 Midterm 1 Review. Tom Zajdel H192 Midterm 1 Review Tom Zajdel Declaring variables Need to specify a type when declaring a variable. Can declare multiple variables in one line. int x, y, z; float a, b, c; Can also initialize in same

More information

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring 2009 Topic Notes: C and Unix Overview This course is about computer organization, but since most of our programming is

More information

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

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors. 1 LECTURE 3 OUTLINES Variable names in MATLAB Examples Matrices, Vectors and Scalar Scalar Vectors Entering a vector Colon operator ( : ) Mathematical operations on vectors examples 2 VARIABLE NAMES IN

More information

Slide Set 5. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Slide Set 5. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary Slide Set 5 for ENCM 339 Fall 2016 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary October 2016 ENCM 339 Fall 2016 Slide Set 5 slide 2/32

More information

Applied 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 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 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

Basics of Programming

Basics of Programming Unit 2 Basics of Programming Problem Analysis When we are going to develop any solution to the problem, we must fully understand the nature of the problem and what we want the program to do. Without the

More information

Computers Programming Course 5. Iulian Năstac

Computers Programming Course 5. Iulian Năstac Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction

More information

BİL200 TUTORIAL-EXERCISES Objective:

BİL200 TUTORIAL-EXERCISES Objective: Objective: The purpose of this tutorial is learning the usage of -preprocessors -header files -printf(), scanf(), gets() functions -logic operators and conditional cases A preprocessor is a program that

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

Function. specific, well-defined task. whenever it is called or invoked. A function to add two numbers A function to find the largest of n numbers

Function. specific, well-defined task. whenever it is called or invoked. A function to add two numbers A function to find the largest of n numbers Functions 1 Function n A program segment that carries out some specific, well-defined task n Example A function to add two numbers A function to find the largest of n numbers n A function will carry out

More information

Advanced C Programming Topics

Advanced C Programming Topics Introductory Medical Device Prototyping Advanced C Programming Topics, http://saliterman.umn.edu/ Department of Biomedical Engineering, University of Minnesota Operations on Bits 1. Recall there are 8

More information

Fundamentals of Programming Session 8

Fundamentals of Programming Session 8 Fundamentals of Programming Session 8 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2013 These slides have been created using Deitel s slides Sharif University of Technology Outlines

More information

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #43. Multidimensional Arrays

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #43. Multidimensional Arrays Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #43 Multidimensional Arrays In this video will look at multi-dimensional arrays. (Refer Slide Time: 00:03) In

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

C Functions. CS 2060 Week 4. Prof. Jonathan Ventura

C Functions. CS 2060 Week 4. Prof. Jonathan Ventura CS 2060 Week 4 1 Modularizing Programs Modularizing programs in C Writing custom functions Header files 2 Function Call Stack The function call stack Stack frames 3 Pass-by-value Pass-by-value and pass-by-reference

More information

Chapter 3. Computer Science & Engineering 155E Computer Science I: Systems Engineering Focus. Existing Information.

Chapter 3. Computer Science & Engineering 155E Computer Science I: Systems Engineering Focus. Existing Information. Chapter 3 Computer Science & Engineering 155E Computer Science I: Systems Engineering Focus Lecture 03 - Introduction To Functions Christopher M. Bourke cbourke@cse.unl.edu 3.1 Building Programs from Existing

More information

C Programs: Simple Statements and Expressions

C Programs: Simple Statements and Expressions .. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar.. C Programs: Simple Statements and Expressions C Program Structure A C program that consists of only one function has the following

More information

Chapter 3: Arrays and More C Functionality

Chapter 3: Arrays and More C Functionality Chapter 3: Arrays and More C Functionality Objectives: (a) Describe how an array is stored in memory. (b) Define a string, and describe how strings are stored. (c) Describe the implications of reading

More information

Multiple Choice Questions ( 1 mark)

Multiple Choice Questions ( 1 mark) Multiple Choice Questions ( 1 mark) Unit-1 1. is a step by step approach to solve any problem.. a) Process b) Programming Language c) Algorithm d) Compiler 2. The process of walking through a program s

More information

AROUND THE WORLD OF C

AROUND THE WORLD OF C CHAPTER AROUND THE WORLD OF C 1 1.1 WELCOME TO C LANGUAGE We want to make you reasonably comfortable with C language. Get ready for an exciting tour. The problem we would consider to introduce C language

More information

Note: unless otherwise stated, the questions are with reference to the C Programming Language. You may use extra sheets if need be.

Note: unless otherwise stated, the questions are with reference to the C Programming Language. You may use extra sheets if need be. CS 156 : COMPUTER SYSTEM CONCEPTS TEST 1 (C PROGRAMMING PART) FEBRUARY 6, 2001 Student s Name: MAXIMUM MARK: 100 Time allowed: 45 minutes Note: unless otherwise stated, the questions are with reference

More information

CpSc 111 Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input

CpSc 111 Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input CpSc Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input Overview For this lab, you will use: one or more of the conditional statements explained below scanf() or fscanf() to read

More information

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 18 I/O in C Standard C Library I/O commands are not included as part of the C language. Instead, they are part of the Standard C Library. A collection of functions and macros that must be implemented

More information

2/5/2018. Expressions are Used to Perform Calculations. ECE 220: Computer Systems & Programming. Our Class Focuses on Four Types of Operator in C

2/5/2018. Expressions are Used to Perform Calculations. ECE 220: Computer Systems & Programming. Our Class Focuses on Four Types of Operator in C University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering ECE 220: Computer Systems & Programming Expressions and Operators in C (Partially a Review) Expressions are Used

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

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

cc is really a front-end program to a number of passes or phases of the whole activity of "converting" our C source files to executable programs:

cc is really a front-end program to a number of passes or phases of the whole activity of converting our C source files to executable programs: 1 next CITS2002 CITS2002 schedule What is cc really doing - the condensed version We understand how cc works in its simplest form: we invoke cc on a single C source file, we know the C-processor is invoked

More information

بسم اهلل الرمحن الرحيم

بسم اهلل الرمحن الرحيم بسم اهلل الرمحن الرحيم Fundamentals of Programming C Session # 10 By: Saeed Haratian Fall 2015 Outlines Examples Using the for Statement switch Multiple-Selection Statement do while Repetition Statement

More information

Program Organization and Comments

Program Organization and Comments C / C++ PROGRAMMING Program Organization and Comments Copyright 2013 Dan McElroy Programming Organization The layout of a program should be fairly straight forward and simple. Although it may just look

More information

Introduction to Computers II Lecture 4. Dr Ali Ziya Alkar Dr Mehmet Demirer

Introduction to Computers II Lecture 4. Dr Ali Ziya Alkar Dr Mehmet Demirer Introduction to Computers II Lecture 4 Dr Ali Ziya Alkar Dr Mehmet Demirer 1 Contents: Utilizing the existing information Top-down design Start with the broadest statement of the problem Works down to

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

Variables are used to store data (numbers, letters, etc) in MATLAB. There are a few rules that must be followed when creating variables in MATLAB:

Variables are used to store data (numbers, letters, etc) in MATLAB. There are a few rules that must be followed when creating variables in MATLAB: Contents VARIABLES... 1 Storing Numerical Data... 2 Limits on Numerical Data... 6 Storing Character Strings... 8 Logical Variables... 9 MATLAB S BUILT-IN VARIABLES AND FUNCTIONS... 9 GETTING HELP IN MATLAB...

More information

Hello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3

Hello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3 Hello, World! in C Johann Myrkraverk Oskarsson October 23, 2018 Contents 1 The Quintessential Example Program 1 I Printing Text 2 II The Main Function 3 III The Header Files 4 IV Compiling and Running

More information

Topic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History

Topic 6: A Quick Intro To C. Reading. goto Considered Harmful History Topic 6: A Quick Intro To C Reading Assumption: All of you know basic Java. Much of C syntax is the same. Also: Some of you have used C or C++. Goal for this topic: you can write & run a simple C program

More information

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 1

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 1 BIL 104E Introduction to Scientific and Engineering Computing Lecture 1 Introduction As engineers and scientists why do we need computers? We use computers to solve a variety of problems ranging from evaluation

More information

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 6: User-Defined Functions I

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 6: User-Defined Functions I C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 6: User-Defined Functions I In this chapter, you will: Objectives Learn about standard (predefined) functions and discover

More information

Have examined process Creating program Have developed program Written in C Source code

Have examined process Creating program Have developed program Written in C Source code Preprocessing, Compiling, Assembling, and Linking Introduction In this lesson will examine Architecture of C program Introduce C preprocessor and preprocessor directives How to use preprocessor s directives

More information