Government Polytechnic Muzaffarpur.

Size: px
Start display at page:

Download "Government Polytechnic Muzaffarpur."

Transcription

1 Government Polytechnic Muzaffarpur. Name of the Lab: COMPUTER PROGRAMMING LAB (MECH. ENGG. GROUP) Subject Code: Experiment: 1 Aim: Programming exercise on executing a C program. If you are looking for C programs, please click here C programs. This C programming basics section explains a simple Hello World C program. Also, it covers below basic topics as well, which are to be known by any C programmer before writing a C program. 1. C programming basic commands to write a C program 2. A simple C program with output and explanation 3. Steps to write C programs and get the output 4. Creation, Compilation and Execution of a C program * How to install C compiler and IDE tool to run C programming codes 5. Basic structure of a C program * Example C program to compare all the sections * Description for each section of the C program 1. C PROGRAMMING BASICS TO WRITE A C PROGRAM: Below are few commands and syntax used in C programming to write a simple C program. Let s see all the sections of a simple C program line by line.

2 C Basic commands #include <stdio.h> int main() /*_some_comments_*/ printf( Hello_World! ); getch(); return 0; Explanation This is a preprocessor command that includes standard input output header file(stdio.h) from the C library before compiling a C program This is the main function from where execution of any C program begins. This indicates the beginning of the main function. whatever is given inside the command /* */ in any C program, won t be considered for compilation and execution. printf command prints the output onto the screen. This command waits for any character input from keyboard. This command terminates C program (main function) and returns 0. This indicates the end of the main function. 2. A SIMPLE C PROGRAM: Below C program is a very simple and basic program in C programming language. This C program displays Hello World! in the output window. And, all syntax and commands in C programming are case sensitive. Also, each statement should be ended with semicolon (;) which is a statement terminator. #include <stdio.h> int main()

3 /* Our first simple C basic program */ printf("hello World! "); getch(); return 0; OUTPUT: Hello World! 3. STEPS TO WRITE C PROGRAMS AND GET THE OUTPUT: Below are the steps to be followed for any C program to create and get the output. This is common to all C program and there is no exception whether its a very small C program or very large C program. 1. Create 2. Compile 3. Execute or Run 4. Get the Output 4. CREATION, COMPILATION AND EXECUTION OF A C PROGRAM:

4 Experiment: 2 Aim: Use of Sequential structure sequence of statements are written in order to accomplish a specific activity. So statements are executed in the order they are specified in the program. This way of executing statements sequentially is known as Sequential control statements. There is an advantage that is no separate control statements are needed in order to execute the statements one after the other. include<stdio.h> main() int arr[50],k,i,l,pos=0; printf( Enter limit For SEQUENTIAL SEARCH\n ); scanf( %d,&l); printf( Enter %d elements\n,l); for(i=0;i<l;i++) scanf( %d,&arr[i]); printf( Enter a number to be search\n ); scanf( %d,&k); for(i=0;i<l;i++) if(arr[i]==k) pos=i+1; break; if(pos!=0) printf( %d is found in the list, at position %d\n,k,pos);

5 else printf( %d is not in the list\n,k); OUTPUT: Enter limit For SEQUENTIAL SEARCH 10 Enter 10 elements Enter a number to be search is found in the list, at position 4

6 Experiment: 3 Aim: Use of if-else statements In decision control statements (if-else and nested if), group of statements are executed when condition is true. If condition is false, then else part statements are executed. There are 3 types of decision making control statements in C language. They are, 1. if statements 2. if else statements 3. nested if statements IF, ELSE AND NESTED IF DECISION CONTROL STATEMENTS IN C: Syntax for each C decision control statements are given in below table with description. Decision control statements if if else Syntax/Description Syntax: if (condition) Statements; Description: In these type of statements, if condition is true, then respective block of code is executed. Syntax: if (condition) Statement1; Statement2; else Statement3; Statement4; Description: In these type of statements, group of statements are executed when condition is true. If condition is false, then else part statements are executed.

7 nested if Syntax: if (condition1) Statement1; else_if(condition2) Statement2; else Statement 3; Description: If condition 1 is false, then condition 2 is checked and statements are executed if it is true. If condition 2 also gets failure, then else part is executed. EXAMPLE PROGRAM FOR IF STATEMENT IN C: In if control statement, respective block of code is executed when condition is true. int main() int m=40,n=40; if (m == n) printf("m and n are equal"); OUTPUT: m and n are equal EXAMPLE PROGRAM FOR IF ELSE STATEMENT IN C: In C if else control statement, group of statements are executed when condition is true. If condition is false, then else part statements are executed. #include <stdio.h> int main() int m=40,n=20;

8 if (m == n) printf("m and n are equal"); else printf("m and n are not equal"); OUTPUT: m and n are not equal EXAMPLE PROGRAM FOR NESTED IF STATEMENT IN C: In nested if control statement, if condition 1 is false, then condition 2 is checked and statements are executed if it is true. If condition 2 also gets failure, then else part is executed. #include <stdio.h> int main() int m=40,n=20; if (m>n) printf("m is greater than n"); else if(m<n) printf("m is less than n"); else printf("m is equal to n"); OUTPUT: m is greater than n

9 Experiment: 4 Aim: Use of for statement. Loop control statements in C are used to perform looping operations until the given condition is true. Control comes out of the loop statements once condition becomes false. TYPES OF LOOP CONTROL STATEMENTS IN C: There are 3 types of loop control statements in C language. They are, 1. for 2. while 3. do-while Syntax for each C loop control statements are given in below table with description. Loop Name for Syntax for (exp1; exp2; expr3) statements; Where, exp1 variable initialization ( Example: i=0, j=2, k=3 ) exp2 condition checking ( Example: i>5, j<3, k=3 ) exp3 increment/decrement ( Example: ++i, j, ++k ) EXAMPLE PROGRAM (FOR LOOP) IN C: In for loop control statement, loop is executed until condition becomes false. #include <stdio.h> int main() int i; for(i=0;i<10;i++)

10 printf("%d ",i); OUTPUT:

11 Experiment:5 Aim: Use of Do-While Statement EXAMPLE PROGRAM (DO WHILE LOOP) IN C: In do..while loop control statement, while loop is executed irrespective of the condition for first time. Then 2 nd time onwards, loop is executed until condition becomes false. do while do statements; while (condition); where, condition might be a>5, i<10 #include <stdio.h> int main() int i=1; do printf("value of i is %d\n",i); i++; while(i<=4 && i>=2); OUTPUT: Value of i is 1 Value of i is 2 Value of i is 3 Value of i is 4

12 Experiment: 6 Aim: Use of While statement EXAMPLE PROGRAM (WHILE LOOP) IN C: In while loop control statement, loop is executed until condition becomes false. while Loop is executed only when condition is true. do while Loop is executed for first time irrespective of the condition. After executing while loop for first time, then c #include <stdio.h> int main() int i=3; while(i<10) printf("%d\n",i); i++; OUTPUT:

13 Experiment: 7 Aim: Use of brake and Continue statement. The statements which are used to execute only specific block of statements in a series of blocks are called case control statements. There are 4 types of case control statements in C language. They are, 1. switch 2. break 3. continue BREAK STATEMENT IN C: Break statement is used to terminate the while loops, switch case loops and for loops from the subsequent execution. Syntax: break; EXAMPLE PROGRAM FOR BREAK STATEMENT IN C: #include <stdio.h> int main() int i; for(i=0;i<10;i++) if(i==5) printf("\ncoming out of for loop when i = 5"); break; printf("%d ",i); OUTPUT:

14 Coming out of for loop when i = 5 CONTINUE STATEMENT IN C: Continue statement is used to continue the next iteration of for loop, while loop and dowhile loops. So, the remaining statements are skipped within the loop for that particular iteration. Syntax : continue; EXAMPLE PROGRAM FOR CONTINUE STATEMENT IN C: #include <stdio.h> int main() int i; for(i=0;i<10;i++) if(i==5 i==6) printf("\nskipping %d from display using " \ "continue statement \n",i); continue; printf("%d ",i); OUTPUT: Skipping 5 from display using continue statement Skipping 6 from display using continue statement 7 8 9

15 Experiment: 8 Aim: Use of multiple branching Switch statement. EXAMPLE PROGRAM FOR SWITCH..CASE STATEMENT IN C: 1. switch case statement in c: switch case statements are used to execute only specific case statements based on the switch expression. below is the syntax for switch case statement. switch (expression) case label1: statements; break; case label2: statements; break; case label3: statements; break; default: statements; break; #include <stdio.h> int main () int value = 3; switch(value) case 1: printf( Value is 1 \n ); break;

16 case 2: printf( Value is 2 \n ); break; case 3: printf( Value is 3 \n ); break; case 4: printf( Value is 4 \n ); break; default : printf( Value is other than 1,2,3,4 \n ); return 0; Output: Value is 3

17 Experiment: 9 Aim: Use of different format specifiers using Scanf( ) and Printf( ) C PROGRAMMING BASICS TO WRITE A C PROGRAM: Below are few commands and syntax used in C programming to write a simple C program. Let s see all the sections of a simple C program line by line. C Basic commands #include <stdio.h> int main() /*_some_comments_*/ printf( Hello_World! ); getch(); return 0; Explanation This is a preprocessor command that includes standard input output header file(stdio.h) from the C library before compiling a C program This is the main function from where execution of any C program begins. This indicates the beginning of the main function. whatever is given inside the command /* */ in any C program, won t be considered for compilation and execution. printf command prints the output onto the screen. This command waits for any character input from keyboard. This command terminates C program (main function) and returns 0. This indicates the end of the main function.

18 2. A SIMPLE C PROGRAM: Below C program is a very simple and basic program in C programming language. This C program displays Hello World! in the output window. And, all syntax and commands in C programming are case sensitive. Also, each statement should be ended with semicolon (;) which is a statement terminator. #include <stdio.h> int main() /* Our first simple C basic program */ printf("hello World! "); getch(); return 0; OUTPUT: Hello World! Scanf(): The scanf function allows you to accept input from standard in, which for us is generally the keyboard. The scanf function can do a lot of different things, but it is generally unreliable unless used in the simplest ways. It is unreliable because it does not handle human errors very well. But for simple programs it is good enough and easy-to-use. 5. BASIC STRUCTURE OF A C PROGRAM: Structure of C program is defined by set of rules called protocol, to be followed by programmer while writing C program. All C programs are having sections/parts which are mentioned below. 1. Documentation section 2. Link Section 3. Definition Section 4. Global declaration section 5. Function prototype declaration section 6. Main function 7. User defined function definition section

19 EXAMPLE C PROGRAM TO COMPARE ALL THE SECTIONS: You can compare all the sections of a C program with the below C program. /* Documentation section C programming basics & structure of C programs */ #include <stdio.h> /* Link section */ int total = 0; /* Global declaration, definition section */ int sum (int, int); /* Function declaration section */ int main () /* Main function */ printf ("This is a C basic program \n"); total = sum (1, 1); printf ("Sum of two numbers : %d \n", total); return 0; int sum (int a, int b) /* User defined function */ return a + b; /* definition section */ OUTPUT: This is a C basic program Sum of two numbers : 2 DESCRIPTION FOR EACH SECTION OF THE C PROGRAM: Let us see about each section of a C basic program in detail below. Please note that a C program mayn t have all below mentioned sections except main function and link sections.

20 Also, a C program structure mayn t be in below mentioned order. Sections Documentation section Link Section Definition Section Global declaration section Function prototype declaration section Main function User defined function section Description We can give comments about the program, creation or modified date, author name etc in this section. The characters or words or anything which are given between /* and */, won t be considered by C compiler for compilation process.these will be ignored by C compiler during compilation. Example : /* comment line1 comment line2 comment 3 */ Header files that are required to execute a C program are included in this section In this section, variables are defined and values are set to these variables. Global variables are defined in this section. When a variable is to be used throughout the program, can be defined in this section. Function prototype gives many information about a function like return type, parameter names used inside the function. Every C program is started from main function and this function contains two major sections called declaration section and executable section. User can define their own functions in this section which perform particular task as per the user requirement.

21 Experiment: 10 Aim: Use of one dimensional array e.g. String, finding standard deviation of a group data. An array is a collection of data that holds fixed number of values of same type. For example: if you want to store marks of 100 students, you can create an array for it. float marks[100]; The size and type of arrays cannot be changed after its declaration. Arrays are of two types: One-dimensional arrays Multidimensional arrays How to declare an array in C? data_type array_name[array_size]; For example, float mark[5]; Here, we declared an array, mark, of floating-point type and size 5. Meaning, it can hold 5 floating-point values. Elements of an Array and How to access them? You can access elements of an array by indices. Suppose you declared an array mark as above. The first element is mark[0], second element is mark[1] and so on. C Array declaration

22 Few key notes: Arrays have 0 as the first index not 1. In this example, mark[0] If the size of an array is n, to access the last element, (n-1) index is used. In this example, mark[4] Suppose the starting address of mark[0] is 2120d. Then, the next address, a[1], will be 2124d, address of a[2] will be 2128d and so on. It's because the size of a float is 4 bytes. How to initialize an array in C programming? It's possible to initialize an array during declaration. For example, int mark[5] = 19, 10, 8, 17, 9; Another method to initialize array during declaration: int mark[] = 19, 10, 8, 17, 9; Initialize an array in C programming Here, mark[0] is equal to 19 mark[1] is equal to 10 mark[2] is equal to 8 mark[3] is equal to 17 mark[4] is equal to 9 How to insert and print array elements? int mark[5] = 19, 10, 8, 17, 9

23 // insert different value to third element mark[3] = 9; // take input from the user and insert in third element scanf("%d", &mark[2]); // take input from the user and insert in (i+1)th element scanf("%d", &mark[i]); // print first element of an array printf("%d", mark[0]); // print ith element of an array printf("%d", mark[i-1]); Example: C Arrays // Program to find the average of n (n < 10) numbers using arrays #include <stdio.h> int main() int marks[10], i, n, sum = 0, average; printf("enter n: "); scanf("%d", &n); for(i=0; i<n; ++i) printf("enter number%d: ",i+1); scanf("%d", &marks[i]); sum += marks[i]; average = sum/n; printf("average = %d", average);

24 return 0; Output Enter n: 5 Enter number1: 45 Enter number2: 35 Enter number3: 38 Enter number4: 31 Enter number5: 49 Average = 39

25 Experiment: 11 Aim: Use of two dimensional array of integers/ reals. In C programming, you can create an array of arrays known as multidimensional array. For example, float x[3][4]; Here, x is a two-dimensional (2d) array. The array can hold 12 elements. You can think the array as table with 3 row and each row has 4 column. Similarly, you can declare a three-dimensional (3d) array. For example, float y[2][4][3]; Here,The array y can hold 24 elements. You can think this example as: Each 2 elements have 4 elements, which makes 8 elements and each 8 elements can have 3 elements. Hence, the total number of elements is 24. How to initialize a multidimensional array? There is more than one way to initialize a multidimensional array.

26 Initialization of a two dimensional array // Different ways to initialize two dimensional array int c[2][3] = 1, 3, 0, -1, 5, 9; int c[][3] = 1, 3, 0, -1, 5, 9; int c[2][3] = 1, 3, 0, -1, 5, 9; Above code are three different ways to initialize a two dimensional arrays. Initialization of a three dimensional array. You can initialize a three dimensional array in a similar way like a two dimensional array. Here's an example, int test[2][3][4] = 3, 4, 2, 3, 0, -3, 9, 11, 23, 12, 23, 2, 13, 4, 56, 3, 5, 9, 3, 5, 3, 1, 4, 9 ; Example #1: Two Dimensional Array to store and display values // C program to store temperature of two cities for a week and display it. #include <stdio.h> const int CITY = 2; const int WEEK = 7; int main() int temperature[city][week]; for (int i = 0; i < CITY; ++i) for(int j = 0; j < WEEK; ++j) printf("city %d, Day %d: ", i+1, j+1);

27 scanf("%d", &temperature[i][j]); printf("\ndisplaying values: \n\n"); for (int i = 0; i < CITY; ++i) for(int j = 0; j < WEEK; ++j) printf("city %d, Day %d = %d\n", i+1, j+1, temperature[i][j]); return 0; Output City 1, Day 1: 33 City 1, Day 2: 34 City 1, Day 3: 35 City 1, Day 4: 33 City 1, Day 5: 32 City 1, Day 6: 31 City 1, Day 7: 30 City 2, Day 1: 23 City 2, Day 2: 22 City 2, Day 3: 21 City 2, Day 4: 24 City 2, Day 5: 22 City 2, Day 6: 25 City 2, Day 7: 26 Displaying values: City 1, Day 1 = 33

28 City 1, Day 2 = 34 City 1, Day 3 = 35 City 1, Day 4 = 33 City 1, Day 5 = 32 City 1, Day 6 = 31 City 1, Day 7 = 30 City 2, Day 1 = 23 City 2, Day 2 = 22 City 2, Day 3 = 21 City 2, Day 4 = 24 City 2, Day 5 = 22 City 2, Day 6 = 25 City 2, Day 7 = 26 Example #2: Sum of two matrices using Two dimensional arrays C program to find the sum of two matrices of order 2*2 using multidimensional arrays. #include <stdio.h> int main() float a[2][2], b[2][2], c[2][2]; int i, j; // Taking input using nested for loop printf("enter elements of 1st matrix\n"); for(i=0; i<2; ++i) for(j=0; j<2; ++j) printf("enter a%d%d: ", i+1, j+1); scanf("%f", &a[i][j]); // Taking input using nested for loop printf("enter elements of 2nd matrix\n");

29 for(i=0; i<2; ++i) for(j=0; j<2; ++j) printf("enter b%d%d: ", i+1, j+1); scanf("%f", &b[i][j]); // adding corresponding elements of two arrays for(i=0; i<2; ++i) for(j=0; j<2; ++j) c[i][j] = a[i][j] + b[i][j]; // Displaying the sum printf("\nsum Of Matrix:"); for(i=0; i<2; ++i) for(j=0; j<2; ++j) printf("%.1f\t", c[i][j]); if(j==1) printf("\n"); return 0; Ouput Enter elements of 1st matrix Enter a11: 2; Enter a12: 0.5; Enter a21: -1.1;

30 Enter a22: 2; Enter elements of 2nd matrix Enter b11: 0.2; Enter b12: 0; Enter b21: 0.23; Enter b22: 23; Sum Of Matrix: Experiment: 12

31 Aim: Defining a function and calling it in the main. function declare in main() and outside main() #include <stdio.h> //void fun(int x,int y, int z); int main() void fun(int x,int y, int z); //Function inside main int a,b,c; printf("..."); scanf("...",...); printf("..."); fun(x,y,z); getchar(); return 0; void fun(int x,int y, int z)... printf(""); 1. WHAT IS C FUNCTION? A large C program is divided into basic building blocks called C function. C function contains set of instructions enclosed by which performs specific operation in a C program. Actually, Collection of these functions creates a C program.

32 2. USES OF C FUNCTIONS: C functions are used to avoid rewriting same logic/code again and again in a program. There is no limit in calling C functions to make use of same functionality wherever required. We can call functions any number of times in a program and from any place in a program. A large C program can easily be tracked when it is divided into functions. The core concept of C functions are, re-usability, dividing a big task into small pieces to achieve the functionality and to improve understandability of very large C programs. 3. C FUNCTION DECLARATION, FUNCTION CALL AND FUNCTION DEFINITION: There are 3 aspects in each C function. They are, Function declaration or prototype This informs compiler about the function name, function parameters and return value s data type. Function call This calls the actual function Function definition This contains all the statements to be executed. C functions aspects syntax function definition Return_type function_name (arguments list) Body of function; function call function_name (arguments list); function declaration return_type function_name (argument list); SIMPLE EXAMPLE PROGRAM FOR C FUNCTION: C As you know, functions should be declared and defined before calling in a C program. In the below program, function square is called from main function. The value of m is passed as argument to the function square. This value is multiplied by itself in this function and multiplied value p is returned to main function from function square.

33 #include<stdio.h> // function prototype, also called function declaration float square ( float x ); // main function, program starts from here int main( ) float m, n ; printf ( "\nenter some number for finding square \n"); scanf ( "%f", &m ) ; // function call n = square ( m ) ; printf ( "\nsquare of the given number %f is %f",m,n ); float square ( float x ) // function definition float p ; p = x * x ; return ( p ) ; 21

34 OUTPUT: Enter some number for finding square 2 Square of the given number is HOW TO CALL C FUNCTIONS IN A PROGRAM? There are two ways that a C function can be called from a program. They are, 1. Call by value 2. Call by reference 1. CALL BY VALUE: Note: In call by value method, the value of the variable is passed to the function as parameter. The value of the actual parameter can not be modified by formal parameter. Different Memory is allocated for both actual and formal parameters. Because, value of actual parameter is copied to formal parameter. Actual parameter This is the argument which is used in function call. Formal parameter This is the argument which is used in function definition EXAMPLE PROGRAM FOR C FUNCTION (USING CALL BY VALUE): C In this program, the values of the variables m and n are passed to the function swap. These values are copied to formal parameters a and b in swap function and used #include<stdio.h> // function prototype, also called function declaration void swap(int a, int b); 4

35 int main() int m = 22, n = 44; // calling swap function by value printf(" values before swap m = %d \nand n = %d", m, n); swap(m, n); void swap(int a, int b) int tmp; tmp = a; a = b; b = tmp; printf(" \nvalues after swap m = %d\n and n = %d", a, b); 20 OUTPUT: values before swap m = 22 and n = 44 values after swap m = 44 and n = CALL BY REFERENCE: In call by reference method, the address of the variable is passed to the function as parameter. The value of the actual parameter can be modified by formal parameter.

36 Same memory is used for both actual and formal parameters since only address is used by both parameters. EXAMPLE PROGRAM FOR C FUNCTION (USING CALL BY REFERENCE): C In this program, the address of the variables m and n are passed to the function swap. These values are not copied to formal parameters a and b in swap function. Because, they are just holding the address of those variables. This address is used to access and change the values of the variables #include<stdio.h> // function prototype, also called function declaration void swap(int *a, int *b); int main() int m = 22, n = 44; // calling swap function by reference printf("values before swap m = %d \n and n = %d",m,n); swap(&m, &n); void swap(int *a, int *b) 14

37 int tmp; tmp = *a; *a = *b; *b = tmp; printf("\n values after swap a = %d \nand b = %d", *a, *b); 20 OUTPUT: values before swap m = 22 and n = 44 values after swap a = 44 and b = 22

Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size];

Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size]; Arrays An array is a collection of two or more adjacent memory cells, called array elements. Array is derived data type that is used to represent collection of data items. C Array is a collection of data

More information

C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS

C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS Manish Dronacharya College Of Engineering, Maharishi Dayanand University, Gurgaon, Haryana, India III. Abstract- C Language History: The C programming language

More information

'C' Programming Language

'C' Programming Language F.Y. Diploma : Sem. II [DE/EJ/ET/EN/EX] 'C' Programming Language Time: 3 Hrs.] Prelim Question Paper Solution [Marks : 70 Q.1 Attempt any FIVE of the following : [10] Q.1(a) Define pointer. Write syntax

More information

Prepared by: Shraddha Modi

Prepared by: Shraddha Modi Prepared by: Shraddha Modi Introduction In looping, a sequence of statements are executed until some conditions for termination of the loop are satisfied. A program loop consist of two segments Body of

More information

An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type.

An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type. Data Structures Introduction An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type. Representation of a large number of homogeneous

More information

Unit 5. Decision Making and Looping. School of Science and Technology INTRODUCTION

Unit 5. Decision Making and Looping. School of Science and Technology INTRODUCTION INTRODUCTION Decision Making and Looping Unit 5 In the previous lessons we have learned about the programming structure, decision making procedure, how to write statements, as well as different types of

More information

Unit 3 Decision making, Looping and Arrays

Unit 3 Decision making, Looping and Arrays Unit 3 Decision making, Looping and Arrays Decision Making During programming, we have a number of situations where we may have to change the order of execution of statements based on certain conditions.

More information

CSE101-Lec#18. Multidimensional Arrays Application of arrays. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU. LPU CSE101 C Programming

CSE101-Lec#18. Multidimensional Arrays Application of arrays. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU. LPU CSE101 C Programming CSE101-Lec#18 Multidimensional Arrays Application of arrays Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU Outline Defining and processing 1D array 2D array Applications of arrays 1-D array A

More information

Module 6: Array in C

Module 6: Array in C 1 Table of Content 1. Introduction 2. Basics of array 3. Types of Array 4. Declaring Arrays 5. Initializing an array 6. Processing an array 7. Summary Learning objectives 1. To understand the concept of

More information

How to declare an array in C?

How to declare an array in C? Introduction An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type. Representation of a large number of homogeneous values.

More information

DECISION CONTROL AND LOOPING STATEMENTS

DECISION CONTROL AND LOOPING STATEMENTS DECISION CONTROL AND LOOPING STATEMENTS DECISION CONTROL STATEMENTS Decision control statements are used to alter the flow of a sequence of instructions. These statements help to jump from one part of

More information

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

COP 3223 Introduction to Programming with C - Study Union - Fall 2017 COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................

More information

{C} Programming. Part 1/2 Basics Variables, Conditions, Loops, Arrays, Pointer basics

{C} Programming. Part 1/2 Basics Variables, Conditions, Loops, Arrays, Pointer basics {C Programming Part 1/2 Basics Variables, Conditions, Loops, Arrays, Pointer basics Variables A variable is a container (storage area) to hold data. Eg. Variable name int potionstrength = 95; Variable

More information

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

COP 3223 Introduction to Programming with C - Study Union - Fall 2017 COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................

More 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 06 - Stephen Scott Adapted from Christopher M. Bourke 1 / 30 Fall 2009 Chapter 8 8.1 Declaring and 8.2 Array Subscripts 8.3 Using

More information

Arrays a kind of data structure that can store a fixedsize sequential collection of elements of the same type. An array is used to store a collection

Arrays a kind of data structure that can store a fixedsize sequential collection of elements of the same type. An array is used to store a collection Morteza Noferesti Arrays a kind of data structure that can store a fixedsize sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful

More information

PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE

PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE 1. Write a C program to perform addition, subtraction, multiplication and division of two numbers. # include # include int a, b,sum,

More information

Decision Making and Loops

Decision Making and Loops Decision Making and Loops Goals of this section Continue looking at decision structures - switch control structures -if-else-if control structures Introduce looping -while loop -do-while loop -simple for

More information

ARRAYS(II Unit Part II)

ARRAYS(II Unit Part II) ARRAYS(II Unit Part II) Array: An array is a collection of two or more adjacent cells of similar type. Each cell in an array is called as array element. Each array should be identified with a meaningful

More information

Introduction. C provides two styles of flow control:

Introduction. C provides two styles of flow control: Introduction C provides two styles of flow control: Branching Looping Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching constructs: if

More information

공학프로그래밍언어 (PROGRAMMING LANGUAGE FOR ENGINEERS) -CONTROL FLOW : LOOP- SPRING 2015, SEON-JU AHN, CNU EE

공학프로그래밍언어 (PROGRAMMING LANGUAGE FOR ENGINEERS) -CONTROL FLOW : LOOP- SPRING 2015, SEON-JU AHN, CNU EE 공학프로그래밍언어 (PROGRAMMING LANGUAGE FOR ENGINEERS) -CONTROL FLOW : LOOP- SPRING 2015, SEON-JU AHN, CNU EE LOOPS WHILE AND FOR while syntax while (expression) statement The expression is evaluated. If it is

More information

Arrays. Example: Run the below program, it will crash in Windows (TurboC Compiler)

Arrays. Example: Run the below program, it will crash in Windows (TurboC Compiler) 1 Arrays General Questions 1. What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array? A. The element will be set to 0. B. The compiler would

More information

UNIT 2 ARRAYS 2.0 INTRODUCTION. Structure. Page Nos.

UNIT 2 ARRAYS 2.0 INTRODUCTION. Structure. Page Nos. UNIT 2 ARRAYS Arrays Structure Page Nos. 2.0 Introduction 23 2.1 Objectives 24 2.2 Arrays and Pointers 24 2.3 Sparse Matrices 25 2.4 Polynomials 28 2.5 Representation of Arrays 30 2.5.1 Row Major Representation

More information

Write a C program using arrays and structure

Write a C program using arrays and structure 03 Arrays and Structutes 3.1 Arrays Declaration and initialization of one dimensional, two dimensional and character arrays, accessing array elements. (10M) 3.2 Declaration and initialization of string

More information

Arrays in C. By Mrs. Manisha Kuveskar.

Arrays in C. By Mrs. Manisha Kuveskar. Arrays in C By Mrs. Manisha Kuveskar. C Programming Arrays An array is a collection of data that holds fixed number of values of same type. For example: if you want to store marks of 100 students, you

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

M1-R4: Programing and Problem Solving using C (JAN 2019)

M1-R4: Programing and Problem Solving using C (JAN 2019) M1-R4: Programing and Problem Solving using C (JAN 2019) Max Marks: 100 M1-R4-07-18 DURATION: 03 Hrs 1. Each question below gives a multiple choice of answers. Choose the most appropriate one and enter

More information

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 2 (Minor modifications by the instructor) 1 Scope Rules A variable declared inside a function is a local variable Each local variable in a function comes into existence when the function

More information

PDS Lab Section 16 Autumn Tutorial 3. C Programming Constructs

PDS Lab Section 16 Autumn Tutorial 3. C Programming Constructs PDS Lab Section 16 Autumn-2017 Tutorial 3 C Programming Constructs This flowchart shows how to find the roots of a Quadratic equation Ax 2 +Bx+C = 0 Start Input A,B,C x B 2 4AC False x If 0 True B x 2A

More information

PDS Class Test 2. Room Sections No of students

PDS Class Test 2. Room Sections No of students PDS Class Test 2 Date: October 27, 2016 Time: 7pm to 8pm Marks: 20 (Weightage 50%) Room Sections No of students V1 Section 8 (All) Section 9 (AE,AG,BT,CE, CH,CS,CY,EC,EE,EX) V2 Section 9 (Rest, if not

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 8 Array typical problems, Search, Sorting Department of Computer Engineering Outline

More information

APS105. Collecting Elements 10/20/2013. Declaring an Array in C. How to collect elements of the same type? Arrays. General form: Example:

APS105. Collecting Elements 10/20/2013. Declaring an Array in C. How to collect elements of the same type? Arrays. General form: Example: Collecting Elements How to collect elements of the same type? Eg:., marks on assignments: APS105 Arrays Textbook Chapters 6.1-6.3 Assn# 1 2 3 4 5 6 Mark 87 89 77 96 87 79 Eg: a solution in math: x 1, x

More information

Fundamentals of Computer Programming Using C

Fundamentals of Computer Programming Using C CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar Faculty Name: Ami D. Trivedi Class: FYBCA Subject: US01CBCA01 (Fundamentals of Computer Programming Using C) *UNIT 3 (Structured Programming, Library Functions

More information

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

COP 3223 Introduction to Programming with C - Study Union - Spring 2018

COP 3223 Introduction to Programming with C - Study Union - Spring 2018 COP 3223 Introduction to Programming with C - Study Union - Spring 2018 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................

More information

UNIVERSITY OF WINDSOR Fall 2007 QUIZ # 2 Solution. Examiner : Ritu Chaturvedi Dated :November 27th, Student Name: Student Number:

UNIVERSITY OF WINDSOR Fall 2007 QUIZ # 2 Solution. Examiner : Ritu Chaturvedi Dated :November 27th, Student Name: Student Number: UNIVERSITY OF WINDSOR 60-106-01 Fall 2007 QUIZ # 2 Solution Examiner : Ritu Chaturvedi Dated :November 27th, 2007. Student Name: Student Number: INSTRUCTIONS (Please Read Carefully) No calculators allowed.

More information

F.Y. Diploma : Sem. II [CO/CD/CM/CW/IF] Programming in C

F.Y. Diploma : Sem. II [CO/CD/CM/CW/IF] Programming in C F.Y. Diploma : Sem. II [CO/CD/CM/CW/IF] Programming in C Time : 3 Hrs.] Prelim Question Paper Solution [Marks : 70 Q.1 Attempt any FIVE of the following : [10] Q.1 (a) List any four relational operators.

More information

Unit 3 Functions. 1 What is user defined function? Explain with example. Define the syntax of function in C.

Unit 3 Functions. 1 What is user defined function? Explain with example. Define the syntax of function in C. 1 What is user defined function? Explain with example. Define the syntax of function in C. A function is a block of code that performs a specific task. The functions which are created by programmer are

More information

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University AN OVERVIEW OF C, PART 3 CSE 130: Introduction to Programming in C Stony Brook University FANCIER OUTPUT FORMATTING Recall that you can insert a text field width value into a printf() format specifier:

More information

Principles of Programming. Chapter 6: Arrays

Principles of Programming. Chapter 6: Arrays Chapter 6: Arrays In this chapter, you will learn about Introduction to Array Array declaration Array initialization Assigning values to array elements Reading values from array elements Simple Searching

More information

It is necessary to have a single function main in every C program, along with other functions used/defined by the programmer.

It is necessary to have a single function main in every C program, along with other functions used/defined by the programmer. Functions A number of statements grouped into a single logical unit are called a function. The use of function makes programming easier since repeated statements can be grouped into functions. Splitting

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

Unit 1 - Arrays. 1 What is an array? Explain with Example. What are the advantages of using an array?

Unit 1 - Arrays. 1 What is an array? Explain with Example. What are the advantages of using an array? 1 What is an array? Explain with Example. What are the advantages of using an array? An array is a fixed-size sequenced collection of elements of the same data type. An array is derived data type. The

More information

C - Basics, Bitwise Operator. Zhaoguo Wang

C - Basics, Bitwise Operator. Zhaoguo Wang C - Basics, Bitwise Operator Zhaoguo Wang Java is the best language!!! NO! C is the best!!!! Languages C Java Python 1972 1995 2000 (2.0) Procedure Object oriented Procedure & object oriented Compiled

More information

Decision Making -Branching. Class Incharge: S. Sasirekha

Decision Making -Branching. Class Incharge: S. Sasirekha Decision Making -Branching Class Incharge: S. Sasirekha Branching The C language programs presented until now follows a sequential form of execution of statements. Many times it is required to alter the

More information

Maltepe University Computer Engineering Department. BİL 133 Algoritma ve Programlama. Chapter 8: Arrays and pointers

Maltepe University Computer Engineering Department. BİL 133 Algoritma ve Programlama. Chapter 8: Arrays and pointers Maltepe University Computer Engineering Department BİL 133 Algoritma ve Programlama Chapter 8: Arrays and pointers Basics int * ptr1, * ptr2; int a[10]; ptr1 = &a[2]; ptr2 = a; // equivalent to ptr2 =

More information

b. array s first element address c. base address of an array d. all elements of an array e. both b and c 9. An array elements are always stored in a.

b. array s first element address c. base address of an array d. all elements of an array e. both b and c 9. An array elements are always stored in a. UNIT IV 1. Appropriately comment on the following declaration int a[20]; a. Array declaration b. array initialization c. pointer array declaration d. integer array of size 20 2. Appropriately comment on

More information

CS6202 - PROGRAMMING & DATA STRUCTURES UNIT I Part - A 1. W hat are Keywords? Keywords are certain reserved words that have standard and pre-defined meaning in C. These keywords can be used only for their

More information

Questions Bank. 14) State any four advantages of using flow-chart

Questions Bank. 14) State any four advantages of using flow-chart Questions Bank Sub:PIC(22228) Course Code:-EJ-2I ----------------------------------------------------------------------------------------------- Chapter:-1 (Overview of C Programming)(10 Marks) 1) State

More information

C library = Header files + Reserved words + main method

C library = Header files + Reserved words + main method DAY 1: What are Libraries and Header files in C. Suppose you need to see an Atlas of a country in your college. What do you need to do? You will first go to the Library of your college and then to the

More information

Arrays. Arrays are of 3 types One dimensional array Two dimensional array Multidimensional array

Arrays. Arrays are of 3 types One dimensional array Two dimensional array Multidimensional array Arrays Array is a collection of similar data types sharing same name or Array is a collection of related data items. Array is a derived data type. Char, float, int etc are fundamental data types used in

More information

WAP 10. WAP 11. WAP 12. WAP 13. WAP 14. WAP 15. WAP 16. WAP 1. : 17. WAP 18. WAP 19. WAP 20. WAP 21. WAP 22. WAP 23. WAP & 24. WAP

WAP 10. WAP 11. WAP 12. WAP 13. WAP 14. WAP 15. WAP 16. WAP 1. : 17. WAP 18. WAP 19. WAP 20. WAP 21. WAP 22. WAP 23. WAP & 24. WAP Contents 1. WAP to accept the value from the user and exchange the values.... 2 2. WAP to check whether the number is even or odd.... 2 3. WAP to Check Odd or Even Using Conditional Operator... 3 4. WAP

More information

IV Unit Second Part STRUCTURES

IV Unit Second Part STRUCTURES STRUCTURES IV Unit Second Part Structure is a very useful derived data type supported in c that allows grouping one or more variables of different data types with a single name. The general syntax of structure

More information

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Basic Science and Humanities

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Basic Science and Humanities PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Basic Science and Humanities Continuous Internal Evaluation Test 2 Date: 0-10- 2017 Marks: 0 Subject &

More information

Programming & Data Structure Laboratory. Day 2, July 24, 2014

Programming & Data Structure Laboratory. Day 2, July 24, 2014 Programming & Data Structure Laboratory Day 2, July 24, 2014 Loops Pre and post test loops for while do-while switch-case Pre-test loop and post-test loop Condition checking True Loop Body False Loop Body

More information

PDS: CS Computer Sc & Engg: IIT Kharagpur 1. for Statement

PDS: CS Computer Sc & Engg: IIT Kharagpur 1. for Statement PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 1 for Statement Another iterative construct in C language is the for-statement (loop). The structure or the syntax of this statement is, for (exp 1 ; exp

More information

Subject: Fundamental of Computer Programming 2068

Subject: Fundamental of Computer Programming 2068 Subject: Fundamental of Computer Programming 2068 1 Write an algorithm and flowchart to determine whether a given integer is odd or even and explain it. Algorithm Step 1: Start Step 2: Read a Step 3: Find

More information

Module 4: Decision-making and forming loops

Module 4: Decision-making and forming loops 1 Module 4: Decision-making and forming loops 1. Introduction 2. Decision making 2.1. Simple if statement 2.2. The if else Statement 2.3. Nested if Statement 3. The switch case 4. Forming loops 4.1. The

More information

Q 1. Attempt any TEN of the following:

Q 1. Attempt any TEN of the following: Subject Code: 17212 Model Answer Page No: 1 / 26 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The

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 9 Pointer Department of Computer Engineering 1/46 Outline Defining and using Pointers

More information

Classification s of Data Structures

Classification s of Data Structures Linear Data Structures using Sequential organization Classification s of Data Structures Types of Data Structures Arrays Declaration of arrays type arrayname [ arraysize ]; Ex-double balance[10]; Arrays

More information

To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows

To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows Unti 4: C Arrays Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type An array is used to store a collection of data, but it is often more useful

More information

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions.

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions. Introduction In the programs that we have dealt with so far, all statements inside the main function were executed in sequence as they appeared, one after the other. This type of sequencing is adequate

More information

Subject: PIC Chapter 2.

Subject: PIC Chapter 2. 02 Decision making 2.1 Decision making and branching if statement (if, if-, -if ladder, nested if-) Switch case statement, break statement. (14M) 2.2 Decision making and looping while, do, do-while statements

More information

Computer Programming Unit 3

Computer Programming Unit 3 POINTERS INTRODUCTION Pointers are important in c-language. Some tasks are performed more easily with pointers such as dynamic memory allocation, cannot be performed without using pointers. So it s very

More information

MODULE 3: Arrays, Functions and Strings

MODULE 3: Arrays, Functions and Strings MODULE 3: Arrays, Functions and Strings Contents covered in this module I. Using an Array II. Functions in C III. Argument Passing IV. Functions and Program Structure, locations of functions V. Function

More information

Programming & Data Structure Laboratory. Arrays, pointers and recursion Day 5, August 5, 2014

Programming & Data Structure Laboratory. Arrays, pointers and recursion Day 5, August 5, 2014 Programming & Data Structure Laboratory rrays, pointers and recursion Day 5, ugust 5, 2014 Pointers and Multidimensional rray Function and Recursion Counting function calls in Fibonacci #include

More information

QUIZ: loops. Write a program that prints the integers from -7 to 15 (inclusive) using: for loop while loop do...while loop

QUIZ: loops. Write a program that prints the integers from -7 to 15 (inclusive) using: for loop while loop do...while loop QUIZ: loops Write a program that prints the integers from -7 to 15 (inclusive) using: for loop while loop do...while loop QUIZ: loops Write a program that prints the integers from -7 to 15 using: for

More information

Lesson 7. Reading and Writing a.k.a. Input and Output

Lesson 7. Reading and Writing a.k.a. Input and Output Lesson 7 Reading and Writing a.k.a. Input and Output Escape sequences for printf strings Source: http://en.wikipedia.org/wiki/escape_sequences_in_c Escape sequences for printf strings Why do we need escape

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 #7 Arrays Part II Passing Array to a Function

More information

Principles of C and Memory Management

Principles of C and Memory Management COMP281 Lecture 8 Principles of C and Memory Management Dr Lei Shi Last Lecture Pointer Basics Previous Lectures Arrays, Arithmetic, Functions Last Lecture Pointer Basics Previous Lectures Arrays, Arithmetic,

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate

More information

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS Syllabus: Pointers and Preprocessors: Pointers and address, pointers and functions (call by reference) arguments, pointers and arrays, address arithmetic, character pointer and functions, pointers to pointer,initialization

More information

Dept. of CSE, IIT KGP

Dept. of CSE, IIT KGP Control Flow: Looping CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Types of Repeated Execution Loop: Group of

More information

& Technology. G) Functions. void. Argument2, Example: (Argument1, Syllabus for 1. 1 What. has a unique. 2) Function name. passed to.

& Technology. G) Functions. void. Argument2, Example: (Argument1, Syllabus for 1. 1 What. has a unique. 2) Function name. passed to. Computer Programming and Utilization (CPU) 110003 G) Functions 1 What is user defined function? Explain with example. Define the syntax of function in C. A function is a block of code that performs a specific

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

Functions. (transfer of parameters, returned values, recursion, function pointers).

Functions. (transfer of parameters, returned values, recursion, function pointers). Functions (transfer of parameters, returned values, recursion, function pointers). A function is a named, independent section of C/C++ code that performs a specific task and optionally returns a value

More information

CSE 2421: Systems I Low-Level Programming and Computer Organization. Functions. Presentation C. Predefined Functions

CSE 2421: Systems I Low-Level Programming and Computer Organization. Functions. Presentation C. Predefined Functions CSE 2421: Systems I Low-Level Programming and Computer Organization Functions Read/Study: Reek Chapters 7 Gojko Babić 01-22-2018 Predefined Functions C comes with libraries of predefined functions E.g.:

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

Lecture 6. Statements

Lecture 6. Statements Lecture 6 Statements 1 Statements This chapter introduces the various forms of C++ statements for composing programs You will learn about Expressions Composed instructions Decision instructions Loop instructions

More information

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

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

More information

MIDTERM TEST EESC 2031 Software Tools June 13, Last Name: First Name: Student ID: EECS user name: TIME LIMIT: 110 minutes

MIDTERM TEST EESC 2031 Software Tools June 13, Last Name: First Name: Student ID: EECS user name: TIME LIMIT: 110 minutes MIDTERM TEST EESC 2031 Software Tools June 13, 2017 Last Name: First Name: Student ID: EECS user name: TIME LIMIT: 110 minutes This is a closed-book test. No books and notes are allowed. Extra space for

More information

Course Outline Introduction to C-Programming

Course Outline Introduction to C-Programming ECE3411 Fall 2015 Lecture 1a. Course Outline Introduction to C-Programming Marten van Dijk, Syed Kamran Haider Department of Electrical & Computer Engineering University of Connecticut Email: {vandijk,

More information

Vidyalankar F.Y. Diploma : Sem. II [CD/CM/CO/CW/DE/ED/EE/EI/EJ/EN/EP/ET/EV/EX/IC/IE/IF/IS/IU/MU] Programming in C

Vidyalankar F.Y. Diploma : Sem. II [CD/CM/CO/CW/DE/ED/EE/EI/EJ/EN/EP/ET/EV/EX/IC/IE/IF/IS/IU/MU] Programming in C F.Y. Diploma : Sem. II [CD/CM/CO/CW/DE/ED/EE/EI/EJ/EN/EP/ET/EV/EX/IC/IE/IF/IS/IU/MU] Programming in C Time : 3 Hrs.] Prelim Question Paper Solution [Marks : 100 Q.1 Attempt any TEN of the following : [20]

More information

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be

More information

UNIT III ARRAYS AND STRINGS

UNIT III ARRAYS AND STRINGS UNIT III ARRAYS AND STRINGS Arrays Initialization Declaration One dimensional and Two dimensional arrays. String- String operations String Arrays. Simple programs- sorting- searching matrix operations.

More information

UNIT - V STRUCTURES AND UNIONS

UNIT - V STRUCTURES AND UNIONS UNIT - V STRUCTURES AND UNIONS STRUCTURE DEFINITION A structure definition creates a format that may be used to declare structure variables. Let us use an example to illustrate the process of structure

More information

COMP 208 Computers in Engineering

COMP 208 Computers in Engineering COMP 208 Computers in Engineering Lecture 14 Jun Wang School of Computer Science McGill University Fall 2007 COMP 208 - Lecture 14 1 Review: basics of C C is case sensitive 2 types of comments: /* */,

More information

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

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University ITC213: STRUCTURED PROGRAMMING Bhaskar Shrestha National College of Computer Studies Tribhuvan University Lecture 08: Control Statements Readings: Chapter 6 Control Statements and Their Types A control

More information

Outline Arrays Examples of array usage Passing arrays to functions 2D arrays Strings Searching arrays Next Time. C Arrays.

Outline Arrays Examples of array usage Passing arrays to functions 2D arrays Strings Searching arrays Next Time. C Arrays. CS 2060 Week 5 1 Arrays Arrays Initializing arrays 2 Examples of array usage 3 Passing arrays to functions 4 2D arrays 2D arrays 5 Strings Using character arrays to store and manipulate strings 6 Searching

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

About Codefrux While the current trends around the world are based on the internet, mobile and its applications, we try to make the most out of it. As for us, we are a well established IT professionals

More information

from Appendix B: Some C Essentials

from Appendix B: Some C Essentials from Appendix B: Some C Essentials tw rev. 22.9.16 If you use or reference these slides or the associated textbook, please cite the original authors work as follows: Toulson, R. & Wilmshurst, T. (2016).

More information

Chapter 8: Function. In this chapter, you will learn about

Chapter 8: Function. In this chapter, you will learn about Principles of Programming Chapter 8: Function In this chapter, you will learn about Introduction to function User-defined function Formal and Actual Parameters Parameter passing by value Parameter passing

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

Computers Programming Course 12. Iulian Năstac

Computers Programming Course 12. Iulian Năstac Computers Programming Course 12 Iulian Năstac Recap from previous course Strings in C The character string is one of the most widely used applications that involves vectors. A string in C is an array of

More information

!"#$% &'($) *+!$ 0!'" 0+'&"$.&0-2$ 10.+3&2),&/3+, %&&/3+, C,-"!.&/+"*0.&('1 :2 %*10% *%7)/ 30'&. 0% /4%./

!#$% &'($) *+!$ 0!' 0+'&$.&0-2$ 10.+3&2),&/3+, %&&/3+, C,-!.&/+*0.&('1 :2 %*10% *%7)/ 30'&. 0% /4%./ 0!'" 0+'&"$ &0-2$ 10 +3&2),&/3+, #include int main() int i, sum, value; sum = 0; printf("enter ten numbers:\n"); for( i = 0; i < 10; i++ ) scanf("%d", &value); sum = sum + value; printf("their

More information

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University ITC213: STRUCTURED PROGRAMMING Bhaskar Shrestha National College of Computer Studies Tribhuvan University Lecture 10: Arrays Readings: Chapter 9 Introduction Group of same type of variables that have same

More information

Multi-Dimensional arrays

Multi-Dimensional arrays Multi-Dimensional arrays An array having more then one dimension is known as multi dimensional arrays. Two dimensional array is also an example of multi dimensional array. One can specify as many dimensions

More information