UNIT III ARRAYS AND STRINGS

Size: px
Start display at page:

Download "UNIT III ARRAYS AND STRINGS"

Transcription

1 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. ARRAYS Definition : Array is a collection of same data type elements under the same variable name referenced by index number. Arrays allow you to store group of data of a single type. Characteristics: Ex: An array is a derived data type. It is used to represent a collection of elements of the same data type. The elements can be access with base address (index) and the subscripts define the position of the element. In array the elements are stored in continuous memory location, the starting memory location is represented by the base address of the array It is easier to refer the array elements by simply incrementing the value of the subscript Array is a linear and homogeneous data structure int a[5]; It tells the compiler that a is an integer type of array and can store 5 integers. Advantages: An array is a derived data type. It is used to represent a collection of elements of the same data type. The elements can be access with base address (index) and the subscripts define the position of the element. In array the elements are stored in continuous memory location, the starting memory location is represented by the base address of the array It is easier to refer the array elements by simply incrementing the value of the subscript GE 6151 Unit III 1

2 Rules of Array: It does not check the boundary. Processing time will increase when working with large data because of increased memory. The array element start with zero not 1. Character array size must be one element greater than data for NULL value. One variable for control structure is required to assign and read value to one dimensional array. Two variable for control structures are required to assign and read value to two dimensional arrays. No two arrays can have the same name but arrays and ordinary variable can be assigned the same name. Classification of arrays: One dimensional Array Two Dimensional Array Multi-Dimensional Array One Dimensional Array: A list of items can be given one variable name using only one subscript and a variable is called one dimensional array or single subscripted variable. Declaration: Arrays are declared in the same manner as an ordinary variables except that array name must have the size of an array Description: Data type-> specifies the type of the data Array name -> specify the name of the array Data_type Array_name[size]; Size -> specify the maximum number of elements that the array can hold Ex: int a[5]; //Here a is integer array with 5 subscript a[0] a[1] a[2] GE 6151 Unit III 2

3 a[3] a[4] Initializing an array: The values can be initialized to an array when they are declared like ordinary variables otherwise they hold garbage values. The array can be initialized in the following two types: o At compile time(static Initialization) o At run time(dynamic Initialization) static Initialization: Data_type Array_name[size] = list of values The list of values must be separated by commas. Ex: Int marks[5]= 70,80,98,35,56; marks[0] marks[1] marks[2] marks[3] marks[4] int age[]=2,4,34,3,4; The elements can be used like ordinary variables Character array can also initialized in similar manner Ex: char name[10]= R, A, J ; The above statements declare the name variables as an array of character with the string LAK. Dynamic Initialization: The array can be explicitly initialized at run time. GE 6151 Unit III 3

4 Ex: int sum[5]; for(int i=0;i<5;i++) sum[i]=i; Like the array can also be initialized by reading data from the user. Ex: int sum[5]; for(int i=0;i<5;i++) scanf( %d,&a[i]); Accessing Array Elements: In C programming, arrays can be accessed and treated like variables in C. #include <stdio.h> void main() int marks[10],i, n, sum=0; printf("enter number of students: "); scanf("%d",&n); for(i=0;i<n;++i) printf("enter marks of student%d: ",i+1); scanf("%d",&marks[i]); sum+=marks[i]; printf("sum= %d",sum); Enter number of students: 3 Enter marks of student1: 12 Enter marks of student2: 31 Enter marks of student3: 2 sum=45 Program to accept 5 numbers and print whether the number is even or odd. #include <stdio.h> #include<conio.h> GE 6151 Unit III 4

5 void main() int array[5], I; clrscr(); printf("enter the elements of the array \n"); for (i = 0; i <5; i++) scanf("%d", &array[i]); printf("even numbers in the array are - "); for (i = 0; i < 5; i++) if (array[i] % 2 == 0) printf("%d \t", array[i]); printf("\n Odd numbers in the array are -"); for (i = 0; i <5; i++) if (array[i] % 2!= 0) printf("%d \t", array[i]); getch(); Two dimensional array: Two dimensional arrays are used in situation where a table of values need to be stored in an array. These can be defined in the same manner as in one dimensional array except a separate pair of square brackets are required for each subscript Data_type Array_name[row_size][column_size]; Two dimensional arrays are stored in a row column matrix where the left index indicated the row and the right index indicated the column. GE 6151 Unit III 5

6 Void main() int a[3][3]=1,2,3,4,5,6,7,8,9; clrscr(); printf( Array Elements and Address\n ); for (i=0;i<3;i++) for(j=0;j<3;j++) printf( %d[%d]\t,a[i][j],&a[i][j]); printf( \n ); 1[2000] 2[2002] 3[2004] 4[2006] 5[2006] 6[2007] 7[2009] 8[2011] 9[2013] Transpose of Matrix #include<stdio.h> #include<conio.h> void main() int r,c,i,j,m[10][10]; clrscr(); printf("enter number of rows and columns:"); scanf("%d %d",&r,&c); for(i=0;i<r;i++) for(j=0;j<c;j++) scanf("%d",&m[i][j]); printf("\nthe Transpose matrix"); for(i=0;i<r;i++) printf("\n"); for(j=0;j<c;j++) printf(" %d",m[j][i]); getch(); GE 6151 Unit III 6

7 Matrix Addition: #include <stdio.h> #include<conio.h> void main() int m, n, c, d, first[10][10], second[10][10], sum[10][10]; clrscr(); printf("enter the number of rows and columns of matrix\n"); scanf("%d%d", &m, &n); printf("enter the elements of first matrix\n"); for (c = 0; c < m; c++) for (d = 0; d < n; d++) scanf("%d", &first[c][d]); printf("enter the elements of second matrix\n"); for (c = 0; c < m; c++) for (d = 0 ; d < n; d++) scanf("%d", &second[c][d]); printf("sum of entered matrices:-\n"); for (c = 0; c < m; c++) for (d = 0 ; d < n; d++) sum[c][d] = first[c][d] + second[c][d]; printf("%d\t", sum[c][d]); printf("\n"); getch(); Matrix Multiplication: #include <stdio.h> #include<conio.h> void main() int m, n, p, q, c, d, k, sum = 0; int first[10][10], second[10][10], multiply[10][10]; clrscr(); printf("enter the number of rows and columns of first matrix\n"); scanf("%d%d", &m, &n); printf("enter the elements of first matrix\n"); GE 6151 Unit III 7

8 for (c = 0; c < m; c++) for (d = 0; d < n; d++) scanf("%d", &first[c][d]); printf("enter the number of rows and columns of second matrix\n"); scanf("%d%d", &p, &q); if (n!= p) printf("matrices with entered orders can't be multiplied with each other.\n"); else printf("enter the elements of second matrix\n"); for (c = 0; c < p; c++) for (d = 0; d < q; d++) scanf("%d", &second[c][d]); for (c = 0; c < m; c++) for (d = 0; d < q; d++) for (k = 0; k < p; k++) sum = sum + first[c][k]*second[k][d]; multiply[c][d] = sum; sum = 0; printf("product of entered matrices:-\n"); for (c = 0; c < m; c++) for (d = 0; d < q; d++) printf("%d\t", multiply[c][d]); printf("\n"); getch(); MULTI DIMENSIONAL ARRAY: An Array with more than two subscripts are called Multi Dimensional Array. GE 6151 Unit III 8

9 data_type Array_name[size1][size2][size3].[sizen]; int a[3][3][4]; float b[4][5][6][8]; Arrays with more than three subscripts are not used often Multi dimensional arrays are slower than single dimensional array. void main() int a[3][3][3],i,j,k; clrscr(); printf( Enter Array Elements:\n ); for (i=0;i<3;i++) for(j=0;j<3;j++) for(k=0;k<3;k++) scanf( %d, &a[i][j][k]); printf( Array Elements are\n ); for (i=0;i<3;i++) printf( \n ); for(j=0;j<3;j++) printf( \n ); for(k=0;k<3;k++) printf( %d\t, &a[i][j][k]); getch(); GE 6151 Unit III 9

10 SORTING Bubble Sort: #include<stdio.h> #include<conio.h> void main( ) int i,j,n,a[20],temp; clrscr( ); printf( Sorting the elements using bubble sort\n ); printf( Enter the size of the array \n ); scanf( %d,&n); printf( Enter the elements of the array:\n ); for(i=0;i<n;i++) scanf( %d,&a[i]); for(i=0;i<n;i++) for(j=0;j<n-1-i;j++) if(a[j]>a[j+1]) temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; printf( The elements sorted using bubble sort are:\n ); for(i=0;i<n;i++) printf( %d\t,a[i]); getch( ); GE 6151 Unit III 10

11 SEARCHING Linear Search: #include <stdio.h> #include<conio.h> void main() int array[100], search, c, n; clrscr(); printf("enter the number of elements in array\n"); scanf("%d",&n); printf("enter %d integer(s)\n", n); for (c = 0; c < n; c++) scanf("%d", &array[c]); printf("enter the number to search\n"); scanf("%d", &search); for (c = 0; c < n; c++) if (array[c] == search) printf("%d is present at location %d.\n", search, c+1); break; if (c == n) printf("%d is not present in array.\n", search); getch(); Binary Search: #include <stdio.h> #include<conio.h> int main() int i, first, last, middle, n, search, array[100]; printf("enter number of elements\n"); scanf("%d",&n); printf("enter %d integers\n", n); for ( i = 0 ; i < n ; i++ ) scanf("%d",&array[i]); printf("enter value to find\n"); GE 6151 Unit III 11

12 scanf("%d",&search); first = 0; last = n - 1; middle = (first+last)/2; while( first <= last ) if ( array[middle] < search ) first = middle + 1; else if ( array[middle] >search ) last=middle+1; else printf("%d found at location %d.\n", search, middle+1); if ( first > last ) printf("not found! %d is not present in the list.\n", search); return 0; String is the collection of characters. STRING In c language, the group of characters, digits and symbols enclosed with in is called string A string is declared as a one dimensional array of characters. The string is terminated by a null( \0 ) character It is not compulsory to add \0 in a string, compiler will automatically puts \0 in a string The string are normally used to manipulate the text such as words and sentences. Header file used is string.h String Declaration: Ex: Datatype variable_name [size]; char name[30]; String Initialization: Ex: Datatype variable_name [size] = string; char name[]= r, a, j, a, \0 ; GE 6151 Unit III 12

13 where the \0 is specified at the end of string C provides another method for initialing string char name[]= raja ; Here \0 is not necessary Reading & writing String: The %s control string can be used in scanf() function to read a string from the terminal. and same may be used to write string to the terminal in printf() function. Ex: char a[10]; scanf( %s, a); printf( %s, a); Built-in String functions/ String Operations/ String Manipulation Functions: There are several string functions to work with string variables and its values. These functions are available C header file called string.h. Consider the following example: char string1[15]= Hello ; char string2[15]= World ; 1) Copying String strcpy(destination,source); Here, source and destination are both the name of the string. This statement, copies the content of string source to the content of string destination. This function will replace the existing value of destination with source. char string1[15]= Hello ; char string2[15]= World ; strcpy(string1,string2); printf( %s%s,string1,string2); output: World World 2) Comparing String: Case Sensitive: This function compares the value from string2 with string1. If both the string1 and string2 are exactly the same then the function will return zero or else it will return some positive or negative value. For the above example the function will return negative of positive value. Here string1 and string2 will not change. GE 6151 Unit III 13

14 strcmp(string1,string2); int n; char string1[15]= Hello ; char string2[15]= Hello ; n=strcmp(string1,string2); printf( %n,n); 0 Non-Case Sensitive: stricmp(string1, string2); int n; char string1[15]= Hello ; char string2[15]= hello ; n=stricmp(string1,string2); printf( %n,n); 0 3) Concatenation String strcat(string1,string2); This function is used to join two strings. It concatenates source string at the end of destination string. Here String 2 is concatenate with String1. char string1[15]= Hello ; char string2[15]= World ; n=strcat(string1,string2); printf( %s,string1); HelloWorld strncat(string1,string2,no_of_characters); This function is used to join two strings. It concatenates portion of source string at the end of destination string. Here String 2 is concatenate with String1. char string1[15]= Hello ; char string2[15]= World ; GE 6151 Unit III 14

15 n=strcat(string1,string2,3); printf( %s,string1); HelloWor 4) Copying String strcpy(string1,string2); This function copy s the contents of one string2 into another string1. char string1[15]= Hello ; char string2[15]= World ; n=strcpy(string1,string2); printf( %s,str1); World strncpy(string1,string2,no_of_characters); This function copies portion of contents of one string2 into another string1. char string1[15]= ; char string2[15]= Hello World ; n=strcpy(string1,string2,5); printf( %s,string1); Hello 5) Find a value in string (strstr()) This function will find the first occurance of string2 in string1. Assume string1 as Apple and string2 as Ap, now the function will return first occurrence of Ap, since Ap is found in Apple. o strstr(string1, string2); char string1[20] = "Hello "; char string2[10] = "World"; printf("the substring is: %s\n", strstr(string1,string2)); World 6) Find a value in string (strrstr()) This function will find the last occurance of string2 in string1. GE 6151 Unit III 15

16 Assume string1 as Apple and string2 as Ap, now the function will return position of first occurrence of Ap, since Ap is found in Apple. o strrstr(string1, string2); char string1[20] = "Hello world "; char string2[10] = "World"; printf("the substring is: %s\n", strrstr(string1,string2)); o World 7) Find a character in string (strchr()) strchr( ) function returns pointer to the first occurrence of the character in a given string strchr(string,chracter); char string1[15]= Hello World ; printf(strchr(string1, l )); 3 8) Duplicate String: strdup( ) function in C duplicates the given string string2=strdup(string1); char string1= Hello ; char string2; string2=strdup(string1); printf( %s,string2); Hello 9) Find a character in string (strrchr()) strchr( ) function returns pointer to the last occurrence of the character in a given string strrchr(string,chracter); char string1[15]= Hello World ; printf(strrchr(string1, l )); GE 6151 Unit III 16

17 10 10) Reversing a string strrev( ) function reverses a given string in C language strrev(string1); char name[30] = "Hello"; printf("string after strrev( ) : %s",strrev(name)); String after strrev( ) : olleh 11) Length of String This function will return length of the string. strlen(string1); int len; char array[20]="hello " ; len = strlen(array) ; printf ( "string length = %d ", len ) ; String Length = 5 12) Convert Lower case to Uppercase strupr( ) function converts a given string into uppercase strlwr(string1); char str[ ] = "Modify This String To Upper"; printf("%s\n",strupr(str)); MODIFY THIS STRING TO UPPER 13) Convert Uppercase to Lower case strlwr( ) function converts a given string into lower case strupr(string1); char str[ ] = " MODIFY This String To LOwer"; printf("%s\n",strlwr(str)); GE 6151 Unit III 17

18 modify this string to lower 14) Set character: sets all character in a string to given character strset(string1,character); char str[ ] = " Hello"; printf("%s\n",strset(str, # )); ##### 15) Set character: sets portion of characters in a string to given character. strnset(string1,character,number); char str[ ] = " Hello"; printf("%s\n",strnset(str, #,4)); ####0w Palindrome of string data #include <stdio.h> #include <conio.h> #include <string.h> int r; char s1[15], s2[15]; void main() clrscr(); printf("enter a string :"); scanf("%s", s1); strcpy(s2,s1); //copy's s1 to another variable s2 strrev(s2); //reverse the value of s2 printf("%s\n", s1); printf("%s\n", s2); r= strcmp(s1,s2); if (r==0) printf("it is a Palindrome %s\n", s1); else printf("it is not a Palindrome %s\n", s1); GE 6151 Unit III 18

19 getch(); Simple Programs: Binary Search #include <stdio.h> void main() int c, first, last, middle, n, search, array[100]; printf("enter number of elements\n"); scanf("%d",&n); printf("enter %d integers\n", n); for (c = 0; c < n; c++) scanf("%d",&array[c]); printf("enter value to find\n"); scanf("%d", &search); first = 0; last = n - 1; middle = (first+last)/2; while (first <= last) if (array[middle] < search) first = middle + 1; else if (array[middle] == search) printf("%d found at location %d.\n", search, middle+1); break; else last = middle - 1; middle = (first + last)/2; if (first > last) printf("not found! %d is not present in the list.\n", search); Insertion Sort: #include <stdio.h> void main() GE 6151 Unit III 19

20 int n, array[1000], c, d, t; printf("enter number of elements\n"); scanf("%d", &n); printf("enter %d integers\n", n); for (c = 0; c < n; c++) scanf("%d", &array[c]); for (c = 1 ; c <= n - 1; c++) d = c; while ( d > 0 && array[d] < array[d-1]) t = array[d]; array[d] = array[d-1]; array[d-1] = t; d--; printf("sorted list in ascending order:\n"); for (c = 0; c <= n - 1; c++) printf("%d\n", array[c]); Selection Sort: #include <stdio.h> void main() int array[100], n, c, d, position, swap; printf("enter number of elements\n"); scanf("%d", &n); printf("enter %d integers\n", n); for ( c = 0 ; c < n ; c++ ) scanf("%d", &array[c]); for ( c = 0 ; c < ( n - 1 ) ; c++ ) position = c; GE 6151 Unit III 20

21 for ( d = c + 1 ; d < n ; d++ ) if ( array[position] > array[d] ) position = d; if ( position!= c ) swap = array[c]; array[c] = array[position]; array[position] = swap; printf("sorted list in ascending order:\n"); for ( c = 0 ; c < n ; c++ ) printf("%d\n", array[c]); Quick Sort: #include<stdio.h> void quicksort(int [10],int,int); void main() int x[20],size,i; printf("enter size of the array: "); scanf("%d",&size); printf("enter %d elements: ",size); for(i=0;i<size;i++) scanf("%d",&x[i]); quicksort(x,0,size-1); printf("sorted elements: "); for(i=0;i<size;i++) printf(" %d",x[i]); void quicksort(int x[10],int first,int last) int pivot,j,temp,i; GE 6151 Unit III 21

22 if(first<last) pivot=first; i=first; j=last; while(i<j) while(x[i]<=x[pivot]&&i<last) i++; while(x[j]>x[pivot]) j--; if(i<j) temp=x[i]; x[i]=x[j]; x[j]=temp; temp=x[pivot]; x[pivot]=x[j]; x[j]=temp; quicksort(x,first,j-1); quicksort(x,j+1,last); GE 6151 Unit III 22

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

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

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

Sorting & Searching. Hours: 10. Marks: 16

Sorting & Searching. Hours: 10. Marks: 16 Sorting & Searching CONTENTS 2.1 Sorting Techniques 1. Introduction 2. Selection sort 3. Insertion sort 4. Bubble sort 5. Merge sort 6. Radix sort ( Only algorithm ) 7. Shell sort ( Only algorithm ) 8.

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

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

DRONACHARYA COLLEGE OF ENGINEERING,GURGAON. Affiliated to M.D.U.,Rohtak. Approved by AICTE DEPARTMENT OF APPIED SEIENCES & HUMANITIES.

DRONACHARYA COLLEGE OF ENGINEERING,GURGAON. Affiliated to M.D.U.,Rohtak. Approved by AICTE DEPARTMENT OF APPIED SEIENCES & HUMANITIES. DRONACHARYA COLLEGE OF ENGINEERING,GURGAON Affiliated to M.D.U.,Rohtak Approved by AICTE DEPARTMENT OF APPIED SEIENCES & HUMANITIES Lab Manual for Fundamental of Computer Programming in C-LAB CSE-103 List

More information

Programming in C Lab

Programming in C Lab Programming in C Lab 1a. Write a program to find biggest number among given 3 numbers. ALGORITHM Step 1 : Start Start 2 : Input a, b, c Start 3 : if a > b goto step 4, otherwise goto step 5 Start 4 : if

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

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Introduction to arrays

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Introduction to arrays CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Introduction to arrays 1 What are Arrays? Arrays are our first example of structured data. Think of a book with pages numbered 1,2,...,400.

More information

BCSE1002: Computer Programming and Problem Solving LAB MANUAL

BCSE1002: Computer Programming and Problem Solving LAB MANUAL LABMANUAL BCSE1002: Computer Programming and Problem Solving LAB MANUAL L T P Course Type Semester Offered Academic Year 2018-2019 Slot Class Room Faculty Details: Name Website link Designation School

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

Characters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters,

Characters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters, Strings Characters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters, decimal digits, special characters and escape

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

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

BITS PILANI, DUBAI CAMPUS DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI FIRST SEMESTER

BITS PILANI, DUBAI CAMPUS DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI FIRST SEMESTER BITS PILANI, DUBAI CAMPUS DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI FIRST SEMESTER 2017-2018 COURSE : COMPUTER PROGRAMMING (CS F111) COMPONENT : Tutorial#4 (SOLUTION) DATE : 09-NOV-2017 Answer 1(a). #include

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) MODEL ANSWER

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) MODEL ANSWER 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

Chapter 8 Character Arrays and Strings

Chapter 8 Character Arrays and Strings Chapter 8 Character Arrays and Strings INTRODUCTION A string is a sequence of characters that is treated as a single data item. String constant: String constant example. \ String constant example.\ \ includes

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

ONE DIMENSIONAL ARRAYS

ONE DIMENSIONAL ARRAYS LECTURE 14 ONE DIMENSIONAL ARRAYS Array : An array is a fixed sized sequenced collection of related data items of same data type. In its simplest form an array can be used to represent a list of numbers

More information

Government Polytechnic Muzaffarpur.

Government Polytechnic Muzaffarpur. Government Polytechnic Muzaffarpur. Name of the Lab: COMPUTER PROGRAMMING LAB (MECH. ENGG. GROUP) Subject Code: 1625408 Experiment: 1 Aim: Programming exercise on executing a C program. If you are looking

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

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

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

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

Test Paper 3 Programming Language Solution Question 1: Briefly describe the structure of a C program. A C program consists of (i) functions and (ii) statements There should be at least one function called

More information

String can be represented as a single-dimensional character type array. Declaration of strings

String can be represented as a single-dimensional character type array. Declaration of strings String String is the collection of characters. An array of characters. String can be represented as a single-dimensional character type array. Declaration of strings char string-name[size]; char address[25];

More information

F.E. Sem. II. Structured Programming Approach

F.E. Sem. II. Structured Programming Approach F.E. Sem. II Structured Programming Approach Time : 3 Hrs.] Mumbai University Examination Paper Solution - May 13 [Marks : 80 Q.1(a) Explain the purpose of following standard library functions : [3] (i)

More information

F.E. Sem. II. Structured Programming Approach

F.E. Sem. II. Structured Programming Approach F.E. Sem. II Structured Programming Approach Time : 3 Hrs.] Mumbai University Examination Paper Solution - May 14 [Marks : 80 Q.1(a) What do you mean by algorithm? Which points you should consider [4]

More information

Yacoub Sabatin Muntaser Abulafi Omar Qaraeen

Yacoub Sabatin Muntaser Abulafi Omar Qaraeen Programming Fundamentals for Engineers - 0702113 6. Arrays Yacoub Sabatin Muntaser Abulafi Omar Qaraeen 1 One-Dimensional Arrays There are times when we need to store a complete list of numbers or other

More information

Columns A[0] A[0][0] = 20 A[0][1] = 30

Columns A[0] A[0][0] = 20 A[0][1] = 30 UNIT Arrays and Strings Part A (mark questions). What is an array? (or) Define array. An array is a collection of same data type elements All elements are stored in continuous locations Array index always

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

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

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

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

List of Programs: Programs: 1. Polynomial addition

List of Programs: Programs: 1. Polynomial addition List of Programs: 1. Polynomial addition 2. Common operations on vectors in c 3. Matrix operation: multiplication, transpose 4. Basic Unit conversion 5. Number conversion: Decimal to binary 6. Number conversion:

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

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

Sample Paper - II Subject Computer Science

Sample Paper - II Subject Computer Science Sample Paper - II Subject Computer Science Max Marks 70 Duration 3 hrs Note:- All questions are compulsory Q1) a) What is significance of My Computer? 2 b) Explain different types of operating systems.

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

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

Data Structure & Algorithms Laboratory Manual (CS 392)

Data Structure & Algorithms Laboratory Manual (CS 392) Institute of Engineering & Management Department of Computer Science & Engineering Data Structure Laboratory for 2 nd year 3 rd semester Code: CS 392 Data Structure & Algorithms Laboratory Manual (CS 392)

More information

Eastern Mediterranean University School of Computing and Technology Information Technology Lecture7 Strings and Characters

Eastern Mediterranean University School of Computing and Technology Information Technology Lecture7 Strings and Characters Eastern Mediterranean University School of Computing and Technology Information Technology Lecture7 Strings and Characters Using Strings The string in C programming language is actually a one-dimensional

More information

Eastern Mediterranean University School of Computing and Technology Information Technology Lecture5 C Characters and Strings

Eastern Mediterranean University School of Computing and Technology Information Technology Lecture5 C Characters and Strings Eastern Mediterranean University School of Computing and Technology Information Technology Lecture5 C Characters and Strings Using Strings The string in C programming language is actually a one-dimensional

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

Structured programming

Structured programming Exercises 6 Version 1.0, 25 October, 2016 Table of Contents 1. Arrays []................................................................... 1 1.1. Declaring arrays.........................................................

More information

Procedural Programming

Procedural Programming Universität Duisburg-Essen PRACTICAL TRAINING TO THE LECTURE Procedural Programming Session Five: Arrays Name: First Name: Tutor: Matriculation-Number: Group-Number: Date: Prof. Dr.Ing. Axel Hunger Dipl.-Ing.

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) Subject Code: 17212 Model Answer Page No: 1/28 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in themodel answer scheme. 2) The model

More information

1. Simple if statement. 2. if else statement. 3. Nested if else statement. 4. else if ladder 1. Simple if statement

1. Simple if statement. 2. if else statement. 3. Nested if else statement. 4. else if ladder 1. Simple if statement UNIT- II: Control Flow: Statements and Blocks, if, switch statements, Loops: while, do-while, for, break and continue, go to and Labels. Arrays and Strings: Introduction, One- dimensional arrays, Declaring

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

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

Chapter 8: Character & String. In this chapter, you ll learn about;

Chapter 8: Character & String. In this chapter, you ll learn about; Chapter 8: Character & String Principles of Programming In this chapter, you ll learn about; Fundamentals of Strings and Characters The difference between an integer digit and a character digit Character

More information

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming 1 2 3 CMPE 013/L and Strings Gabriel Hugh Elkaim Spring 2013 4 Definition are variables that can store many items of the same type. The individual items known as elements, are stored sequentially and are

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

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

THE BAPATLA ENGINEERING COLLEGE:: BAPATLA DEPARTMENT OF MCA. Subject name: C programing Lab. Subject code: MCA 107. LAB manual of c programing lab

THE BAPATLA ENGINEERING COLLEGE:: BAPATLA DEPARTMENT OF MCA. Subject name: C programing Lab. Subject code: MCA 107. LAB manual of c programing lab THE BAPATLA ENGINEERING COLLEGE:: BAPATLA DEPARTMENT OF MCA Subject name: C programing Lab Subject code: MCA 107 LAB manual of c programing lab 1. Write a C program for calculating compound interest. #include

More information

Strings and Library Functions

Strings and Library Functions Unit 4 String String is an array of character. Strings and Library Functions A string variable is a variable declared as array of character. The general format of declaring string is: char string_name

More information

C Arrays. Group of consecutive memory locations Same name and type. Array name + position number. Array elements are like normal variables

C Arrays. Group of consecutive memory locations Same name and type. Array name + position number. Array elements are like normal variables 1 6 C Arrays 6.2 Arrays 2 Array Group of consecutive memory locations Same name and type To refer to an element, specify Array name + position number arrayname[ position number ] First element at position

More information

DEV BHOOMI INSTITUE OF TECHNOLOGY DEHRADUN Department Of Computer Application. Design and Analysis of Algorithms Lab MCA-302

DEV BHOOMI INSTITUE OF TECHNOLOGY DEHRADUN Department Of Computer Application. Design and Analysis of Algorithms Lab MCA-302 DEV BHOOMI INSTITUE OF TECHNOLOGY DEHRADUN Department Of Computer Application Design and Analysis of Algorithms Lab MCA-302 1 INDEX S.No. PRACTICAL NAME DATE PAGE NO. SIGNATURE 1. Write a Program to Implement

More information

Chapter 7 Solved problems

Chapter 7 Solved problems Chapter 7 7.4, Section D 20. The coefficients of a polynomial function are stored in a single-dimensional array. Display its derivative. If the polynomial function is p(x) = a n x n + a n-1 x n-1 + + a

More information

Array. Arrays. Declaring Arrays. Using Arrays

Array. Arrays. Declaring Arrays. Using Arrays Arrays CS215 Peter Lo 2004 1 Array Array Group of consecutive memory locations Same name and type To refer to an element, specify Array name Position number Format: arrayname[ position number] First element

More information

PES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo

PES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo PES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo 1. (a)what is an algorithm? Draw a flowchart to print N terms of Fibonacci

More information

7.STRINGS. Data Structure Management (330701) 1

7.STRINGS. Data Structure Management (330701)   1 Strings and their representation String is defined as a sequence of characters. 7.STRINGS In terms of c language string is an array of characters. While storing the string in character array the size of

More information

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 Code: DC-05 Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 NOTE: There are 11 Questions in all. Question 1 is compulsory and carries 16 marks. Answer to Q. 1. must be written in the space

More information

Array Initialization

Array Initialization Array Initialization Array declarations can specify initializations for the elements of the array: int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 ; initializes primes[0] to 2, primes[1] to 3, primes[2]

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 6 - Array and String Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Array Generic declaration: typename variablename[size]; typename is

More information

UNIT 6. STRUCTURED DATA TYPES PART 1: ARRAYS

UNIT 6. STRUCTURED DATA TYPES PART 1: ARRAYS UNIT 6. STRUCTURED DATA TYPES PART 1: ARRAYS Programming Year 2017-2018 Industrial Technology Engineering Paula de Toledo Contents 1. Structured data types vs simple data types 2. Arrays (vectors and matrices)

More information

Contents ARRAYS. Introduction:

Contents ARRAYS. Introduction: UNIT-III ARRAYS AND STRINGS Contents Single and Multidimensional Arrays: Array Declaration and Initialization of arrays Arrays as function arguments. Strings: Initialization and String handling functions.

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 Programming Lecture 14 Arrays (Part 2)

Computer Programming Lecture 14 Arrays (Part 2) Computer Programming Lecture 14 Arrays (Part 2) Assist.Prof.Dr. Nükhet ÖZBEK Ege University Department of Electrical & Electronics Engineering nukhet.ozbek@ege.edu.tr 1 Topics The relationship between

More information

1) Write a C Program to check whether given year is Leap year or not. AIM: A C Program to check whether given year is Leap year or not.

1) Write a C Program to check whether given year is Leap year or not. AIM: A C Program to check whether given year is Leap year or not. 1) Write a C Program to check whether given year is Leap year or not. AIM: A C Program to check whether given year is Leap year or not. #include int year; printf("enter a year:"); scanf("%d",&year);

More information

Test Paper 1 Programming Language 1(a) What is a variable and value of a variable? A variable is an identifier and declared in a program which hold a value defined by its type e.g. integer, character etc.

More information

C does not support string data type. Strings in C are represented by arrays of characters.

C does not support string data type. Strings in C are represented by arrays of characters. Chapter 8 STRINGS LEARNING OBJECTIVES After going this chapter the reader will be able to Use different input/output functions for string Learn the usage of important string manipulation functions available

More information

Question Bank (SPA SEM II)

Question Bank (SPA SEM II) Question Bank (SPA SEM II) 1. Storage classes in C (Refer notes Page No 52) 2. Difference between function declaration and function definition (This question is solved in the note book). But solution is

More information

Principles of C and Memory Management

Principles of C and Memory Management COMP281 Lecture 9 Principles of C and Memory Management Dr Lei Shi Last Lecture Today Pointer to Array Pointer Arithmetic Pointer with Functions struct Storage classes typedef union String struct struct

More information

Two Dimensional Array - An array with a multiple indexs.

Two Dimensional Array - An array with a multiple indexs. LAB5 : Arrays Objectives: 1. To learn how to use C array as a counter. 2. To learn how to add an element to the array. 3. To learn how to delete an element from the array. 4. To learn how to declare two

More information

UNIT- I INTRODUCTION TO PROBLEM SOLVING TECHNIQUES

UNIT- I INTRODUCTION TO PROBLEM SOLVING TECHNIQUES UNIT- I INTRODUCTION TO PROBLEM SOLVING TECHNIQUES Short Answer Type Questions - 2 Marks 1. Define Algorithm. A. Definition: A set of sequential steps usually written in Ordinary Language to solve a given

More information

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING APS 105 Computer Fundamentals Final Examination December 16, 2013 2:00 p.m. 4:30 p.m. (150 minutes) Examiners: J. Anderson, B. Korst, J.

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

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

Chapter4: Data Structures. Data: It is a collection of raw facts that has implicit meaning.

Chapter4: Data Structures. Data: It is a collection of raw facts that has implicit meaning. Chapter4: s Data: It is a collection of raw facts that has implicit meaning. Data may be single valued like ID, or multi valued like address. Information: It is the processed data having explicit meaning.

More information

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING APS 105 Computer Fundamentals Final Examination December 14, 2012 2:00 p.m. 4:30 p.m. (150 minutes) Examiners: J. Anderson, B. Li, M. Sadoghi,

More information

DHANALAKSHMI SRINIVASAN INSTITUTE OF RESEARCH AND TECHNOLOGY SIRUVACHUR, PERAMBALUR

DHANALAKSHMI SRINIVASAN INSTITUTE OF RESEARCH AND TECHNOLOGY SIRUVACHUR, PERAMBALUR DHANALAKSHMI SRINIVASAN INSTITUTE OF RESEARCH AND TECHNOLOGY SIRUVACHUR, PERAMBALUR 621 113 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I

More information

UNDERSTANDING THE COMPUTER S MEMORY

UNDERSTANDING THE COMPUTER S MEMORY POINTERS UNDERSTANDING THE COMPUTER S MEMORY Every computer has a primary memory. All our data and programs need to be placed in the primary memory for execution. The primary memory or RAM (Random Access

More information

Computers Programming Course 11. Iulian Năstac

Computers Programming Course 11. Iulian Năstac Computers Programming Course 11 Iulian Năstac Recap from previous course Cap. Matrices (Arrays) Matrix representation is a method used by a computer language to store matrices of different dimension in

More information

NCS 301 DATA STRUCTURE USING C

NCS 301 DATA STRUCTURE USING C NCS 301 DATA STRUCTURE USING C Unit-1 Part-3 Arrays Hammad Mashkoor Lari Assistant Professor Allenhouse Institute of Technology www.ncs301ds.wordpress.com Introduction Array is a contiguous memory of homogeneous

More information

Saini Technologies ADVANCED C PROGRAMMING WITH SAINI TECHNOLOGIES. Sushil Kumar Saini Mo.

Saini Technologies ADVANCED C PROGRAMMING WITH SAINI TECHNOLOGIES. Sushil Kumar Saini   Mo. Saini Technologies ADVANCED C PROGRAMMING WITH SAINI TECHNOLOGIES Sushil Kumar Saini Email: Sushilsaini04@gmail.com Mo. 9896470047 Integer Array int a[]=12,34,54,45,34,34; printf("%d",a[0]); printf(" %d",a[1]);

More information

int marks[10]; // fixed size and fixed address No change in Memory address.

int marks[10]; // fixed size and fixed address No change in Memory address. Dynamic Memory Allocation : Used When we want to allocate memory during run time. int marks[10]; // fixed size and fixed address No change in Memory address. // fixed size. ( no change in size possible

More information

Midterm Examination # 2 Wednesday, March 18, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:

Midterm Examination # 2 Wednesday, March 18, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER: Page 1 of 8 School of Computer Science 60-141-01 Introduction to Algorithms and Programming Winter 2015 Midterm Examination # 2 Wednesday, March 18, 2015 ANSWERS Duration of examination: 75 minutes STUDENT

More information

// CSE/CE/IT 124 JULY 2015, 2.a. algorithm to inverse the digits of a given integer. Step 1: Start Step 2: Read: NUMBER Step 3: r=0,rev=0

// CSE/CE/IT 124 JULY 2015, 2.a. algorithm to inverse the digits of a given integer. Step 1: Start Step 2: Read: NUMBER Step 3: r=0,rev=0 // CSE/CE/IT 124 JULY 2015, 2a algorithm to inverse the digits of a given integer Step 1: Start Step 2: Read: NUMBER Step 3: r=0,rev=0 Step 4: repeat until NUMBER > 0 r=number%10; rev=rev*10+r; NUMBER=NUMBER/10;

More information

Unit 8. Structures and Unions. School of Science and Technology INTRODUCTION

Unit 8. Structures and Unions. School of Science and Technology INTRODUCTION INTRODUCTION Structures and Unions Unit 8 In the previous unit 7 we have studied about C functions and their declarations, definitions, initializations. Also we have learned importance of local and global

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

Programming for Engineers Arrays

Programming for Engineers Arrays Programming for Engineers Arrays ICEN 200 Spring 2018 Prof. Dola Saha 1 Array Ø Arrays are data structures consisting of related data items of the same type. Ø A group of contiguous memory locations that

More information

UNIT-I Input/ Output functions and other library functions

UNIT-I Input/ Output functions and other library functions Input and Output functions UNIT-I Input/ Output functions and other library functions All the input/output operations are carried out through function calls. There exists several functions that become

More information

Tribhuvan University Institute of Science and Technology 2065

Tribhuvan University Institute of Science and Technology 2065 1CSc.102-2065 2065 Candidates are required to give their answers in their own words as for as practicable. 1. Draw the flow chart for finding largest of three numbers and write an algorithm and explain

More information

Unit III Functions. C functions can be classified into two categories, namely, library functions and user defined functions.

Unit III Functions. C functions can be classified into two categories, namely, library functions and user defined functions. Unit III Functions Functions: Function Definition, Function prototype, types of User Defined Functions, Function calling mechanisms, Built-in string handling and character handling functions, recursion,

More information

Content. In this chapter, you will learn:

Content. In this chapter, you will learn: ARRAYS & HEAP Content In this chapter, you will learn: To introduce the array data structure To understand the use of arrays To understand how to define an array, initialize an array and refer to individual

More information

int Return the number of characters in string s.

int Return the number of characters in string s. 1a.String handling functions: Function strcmp(const char *s1, const char *s2) strcpy(char *s1, const char *s2) strlen(const char *) strcat(char *s1, Data type returned int Task Compare two strings lexicographically.

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 7 Array and String Department of Computer Engineering Outline Array String Department

More information