Size: px
Start display at page:

Download ""

Transcription

1 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 main function and other user defined functions may exist in a program. A function has (i) function definition e.g. main() is name of the main function and a function can either return a value or not. If a function does not return a value is defined as void main(). But any other function may return value of some type like integer, char etc. int add(int a, int b); int sum; sum=add(3,4); printf( %d, sum); int add(int a, int b) return(a+b); In the above program, main function is defined as because it doesn t return any value but an user defined function add() is also defined and written which returns a value of integer type. Every function header is immediately followed by opening and closing parenthesis. There can either be no arguments or one or more arguments. In the above program, main function has no arguments but function add has two arguments in which both the parameters are defined by the data type (int a, int b). Statements are written in each and every function. In the above program, statements are written in both the functions main() and add() like sum=add(3,4), printf( %d,sum); and return(a+b);. Any compound statements can also be written within any function. Question 2: Draw the flowchart that shows the process of compiling and running a C program.

2 start Encode and Edit the program Compile Yes Error No Link Run Question 3: Briefly explain different form of main function of a C program A program written in C language must consist of a main function. A main function can either be a function with no returning value with no argumentation or it can return any type of data value with parameter passing In the above program segment, a main function is defined as void that returns no value and no parameter specified within the parenthesis (). Another form of main function is shown below. End

3 addition.cpp int main(int argc[],argv[]) int sum; if(argc[]==0)printf( No input value specified ); else if(argc[]=2)sum=argv[0]+argv[1]; return(sum); The above program receives input values through command line arguments and add them together and return the integer type result of summation of the input values. Question 4: Write a program to find the area of a circle. #define PI float radius, area; printf( Enter Radidus: ); scanf( %f,radius); area=pi*radius*radius; printf( Area of the circle: %7.3f,area); Question 5: What are trigraph characters? How are they useful? Trigraph characters are sequence of three characters that represent one character from ASCII character set. This is ANSI standard practice in C language. This feature may not be available in Turbo C compiler. Usage of trigraph sequence is shown in the following example. Printf( Hellow world??!#n ); While executing the above statement, the output will appear as follows: Hellow world Here two successive question sign followed by exclamatory sign which completes a trigraph sequence will produce a which is a character of ASCII character set on the output screen immediately after the text. A list of trigraph sequence is shown below.??= #??( [??/ \??) ]??' ^??<??!??>??- ~

4 Question 6: How do variables and symbolic names differ? Show with example. A variable is declared with the data type and its name, e.g. int x; here x is a variable name that holds integer type of data. x is variable written in a main function that comes into existence while executing. But symbolic names also known as symbolic constant are defined above the main function just immediately after the header files included conventionally, e.g. #define PI 3.14 Here PI is a symbolic constant with value 3.14 that cannot be changed throughout the program. Question 7: What are the rules for declaring identifiers? Variables, functions and arrays are treated as identifiers. Identifiers are consist of letters and digits as well as the first character must be a letter, both upper case and lower case letters are permitted though lower case letters are usually considered for practice. In this case, upper case letter and lower case letter is not equivalent. An underscore (_) character can also be included in an identifier. Question 8: What is storage class? What are the meaning of storage class? Storage class refers to the permanence of a variable and its scope within a progam that the portion of the program over which the variable is recognized. The four different storage class specifications are automatic, external, static and register identified by the keyword auto, extern, static and register respectively. Automatic variables are always declared within a function and are local to the functions in which they are declared. External variables scopes are extended from the point of their definition to the rest of the program. Static variables are defined within individual functions and have same scope as automatic variables. Question 9: Write a program to convert the given temperature in Fahrenhite to Celcius and vice versa. Formula: (i) C(9/5)+32=F (ii) (F-32)(5/9)=C

5 void ftoc(); //function prototype void ctof(); //function prototype int choice; clrscr(); printf( [1]. Farhenhite to Celcius [2]. Celcius to Farhenhitle\n ); printf( Type 1 or 2 for conversion mode: ); scanf( %d,&choice); if (choice==1)ftoc(); else if (choice==2)ctof(); else printf( Error in choice... ); void ftoc() float f,c; printf( \n ); printf( Enter Farhenhite temperature: ); scanf( %f,&f); c=(f-32.0)*(5.0/9.0); printf( The temperature in celcius: %f,c); return; void ctof() float f,c; printf( \n ); printf( Enter celcius temperature: ); scanf( %f,&c); f=c*(9.0/5.0)+32.0; printf( The temperature in farhentile: %f,f); return; Question 10: Describe nesting of IF-ELSE statement with flow chart an example. A general form of nested if-else: If <condition 1> if <condition 2> <expression 1> else if <condition 3> <expression 2> else <expression 3>. The flowchart of above nested if structure is shown below.

6 No cond1 Yes No Cond2 Yes exp 3 exp 2 exp 1 Question 11: Write down the De-Morgan s rule in the case of decision making and branching. De-Morgan s rule tells us to convert a logical expression into such a form that consists of a NOT operator. For example if the value of i is less than 8 then iterate. According De-Morgan s rule, this expression will become if the value of i not greater than 8 then iterate. Using C syntax, it can be written as while (!(i>8))... Question 12: Write a program that read the value of x and evaluate the following function using if statement and?: operator. 1 for x > 0 y = 0 for x = 0 1 for x < 0 (i) using if statement: float x; int y; printf( Enter value of x: ); scanf( %d,&f); if (x>1.0)y=1; else if (x==0.0)y=0; else if (x<0.0)y=-1; printf( y = %d,y);

7 (ii) using?: operator float x; int y; printf( Enter value of x: ); scanf( %d,&f); y=(x>1.0)? 1 : ((x==0.0)? 0 : -1); printf( y = %d,y); Question 13: What is array? Why an array is called structured data types? An array is a series of objects where all the objects are of same type. The general form of declaration of array is <storage class> <data type> array_name[expression]; For example, an array named x is declared with the size of 10 objects of all integer types Int x[10]; Question 14: Write a program to set all diagonal elements of a two dimensional array to 1 and others to 0. int x[20][20]; int i,j,n; clrscr(); printf("enter size of a square matrix [less than 20]: "); scanf("%d",&n); // putting 0s to all matrix elements for(j=0;j<n;j++) x[i][j]=0;

8 // substituing 1s on the left diagonal for(j=0;j<n;j++) if(i==j)x[i][j]=1; // substituting 1s on the right diagonal j=0; for(i=n-1;i>=0;i--) x[i][j]=1; j++; // printing the matrix for(j=0;j<n;j++) printf("%d ",x[i][j]); Question 15: Character string in C terminates with null character. Explain how this feature helps in string manipulation. In C language Strings are defined as an array of characters or a pointer to a portion of memory containing ASCII characters. A string in C is a sequence of zero or more characters followed by a NULL '\0' character. It is important to preserve the NULL terminating character as it is how C defines and manages variable length strings. If we were to have an array of characters WITHOUT the null character as the last element, we'd have an ordinary character array, rather than a string constant. String constants have double quote marks around them, and can be assigned to char pointers. Alternatively, we can assign a string constant to a char array - either with no size specified, or we can specify a size, but we should leave a space for the null character! Question 16: Briefly explain atoi() with suitable example. atoi function converts a string into an int value. It includes whitespace, punctuation and characters other that E and e. It returns only the integer part of the value returned and decimal part is truncated. Example #include <stdlib.h>

9 char str1[100],str2[100]; printf( Type first string: ); gets(str1); printf( Type another string: ); gets(str2); printf( Ths sum is %d, atoi(str1)+atoi(str2)); return 0; Question 17: Find errors, if any, in the following code segments (a) char str[10]; strncpy(str, GOD,3); printf( %s, str); (b) char str[10]; strcpy(str, Balagursami ); (c) if(strstr( Balagurusami, guru )==0);printf( Substring is found ); (d) char s1[5],s2[10]; gets(s1,s2); (e) char s1[]= Hello, s2[]- World,s3[8]; strcpy(strcat(s1,s2),s3); (a) char str[10]; strcpy(str, GOD ); printf( %s,str); (b) char str[20]; strcpy(str, Balagurusami ); (c) if(strcat( Balagurusami, guru )==0)printf( Substring is found ); (d) char s1[5],s2[10]; gets(s1); gets(s2) (e) char s1[]= Hello, s2[]= World, s3[10]; strcpy(s3,strcat(s1,s2)); Question 18: Describe different types of string-handling functions with meaning and example. Some different string handling functions are: strcat(str1,str2); This function concatenates two strings str1 and str2 and store the resulting string into str1. strcpy(str1,str2); This function copies the string of str2 into str1 strcmp(str1,str2); This function compares str1 and str2. If str1 and str2 matches then it returns 0.

10 strlen(str1); This function computes and returns the length of the string str1. strstr(str1,str2); This function determines the occurrence of str2 in str1. Question 19: Write a program to find the number and sum of all integers greater than 100 and less than 200 that are divisible by 7 using function. int generate_number(int x);//function prototype int summation(int x[],int n);//function prototype int i,index,sum,temp; int values[100]; clrscr(); index=0; for(i=100;i<=200;i++) temp=generate_number(i); if(temp!=0) values[index]=temp; index++; sum=summation(values,index); printf("sum = %d",sum); int generate_number(int x) if((x%7)==0) printf("%d, ",x); return(x); else return 0; int summation(int x[],int n) int s,i; s=0;

11 s=s+x[i]; return(s); Question 20: Write a program in C to add and subtract two same size matrix. int matrix1[100][100],matrix2[100][100]; int matrix_added[100][100],matrix_subtracted[100][100]; int m,n,i,j; // input values to matrices clrscr(); printf("enter size of the matrices [m*n]"); printf("\n m=? "); scanf("%d",&m); printf("\n n=? "); scanf("%d",&n); printf("\nmatrix 1:\n"); printf("cell [i][j]:"); scanf("%d",&matrix1[i][j]); printf("\nmatrix 2:\n"); printf("cell [i][j]:"); scanf("%d",&matrix2[i][j]); // displaying the input matrices clrscr(); printf("the input matrices are..."); printf("\nmatrix 1:\n"); printf("%d ",matrix1[i][j]);

12 printf("\npress Enter... "); printf("\nmatrix 2:\n"); printf("%d ",matrix2[i][j]); printf("\npress Enter... "); //adding two matrics matrix_added[i][j]=matrix1[i][j]+matrix2[i][j]; //dispalying the matrix addition clrscr(); printf("\ntwo matrices added:\n"); printf("%d ",matrix_added[i][j]); printf("\npress Enter..."); //subtracting two matrics matrix_subtracted[i][j]=matrix1[i][j]-matrix2[i][j]; //dispalying the matrix subtraction printf("\ntwo matrices subtracted:\n"); printf("%d ",matrix_subtracted[i][j]);

13 printf("\npress Enter..."); Question 21: What is pointer? Write down the benefits of pointer uses in C program. Pointer is variable whose value is the address or memory location of another variable. For example, pu=&u; pu is a variable which holds the address of the variable u. Here pu is a pointer to u and pu is defined as follows. int *pu; Benefits of using pointers: pointers are generally useful in the context where we need a continuous memory allocation. Using pointers dynamic allocation of memory is achieved pointers basically hold the address of a variable. they are mainly used as function parameters to pass values of parameters as references rather than values Question 22: How can you define a FILE in C? Describe the opening and closing function of a FILE. A file is defined in C in following manner. FILE *fp; Here FILE is a keyword and a file pointer fp is associated with it. A file can be opened with various mode of operation. If a file named Sample.dat is opened with read mode then we can write in C language as follows. fopen( Sample.dat, r ); When the file is to be closed after read operation which was associated with file pointer fp, then the file should be closed in following manner. fclose(fp); Question 23: A file named DATA contains a series of integer numbers. Code a program to read these numbers and then write all odd numbers to a file to be called ODD and all even numbers to a file to be called EVEN.

14 #include <dos.h> int i; FILE *fp; fp=fopen("sample.dat","w"); if(fp==null)printf("file cannot be opened!"); else clrscr(); printf("data are being written... \n"); for(i=1;i<=100;i++) fprintf(fp,"%d ",i); printf("%d ",i); delay(100); fclose(fp); printf("\ndata Saved."); In the above program SAMPLE.DAT file is created and 100 natural integers are written in the SAMPLE.DAT file. In the next program the abovementioned file is opened in read only mode and each and every integer is checked whether is odd or even and written into ODD.DAT and EVEN.DAT files respectively. int num; FILE *fpt, *fpt1, *fpt2; fpt=fopen("sample.dat","r"); if(fpt==null) printf("file cannot be opened!"); else fpt1=fopen("odd.dat","w"); fpt2=fopen("even.dat","w"); printf("\ndata being extracted and saved in ODD and EVEN file..."); while((fscanf(fpt,"%d ",&num))!=eof) if((num%2)==0)

15 fprintf(fpt2,"%d ",num); else fprintf(fpt1,"%d ",num); fclose(fpt1); fclose(fpt2); printf("\ndata saved."); fclose(fpt);

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

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

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

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

'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

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

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

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

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

Model Viva Questions for Programming in C lab

Model Viva Questions for Programming in C lab Model Viva Questions for Programming in C lab Title of the Practical: Assignment to prepare general algorithms and flow chart. Q1: What is a flowchart? A1: A flowchart is a diagram that shows a continuous

More information

VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANGULATHUR

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

More information

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

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

Unit 6 Files. putchar(ch); ch = getc (fp); //Reads single character from file and advances position to next character

Unit 6 Files. putchar(ch); ch = getc (fp); //Reads single character from file and advances position to next character 1. What is File management? In real life, we want to store data permanently so that later on we can retrieve it and reuse it. A file is a collection of bytes stored on a secondary storage device like hard

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

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

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

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

More information

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

Unit 7. Functions. Need of User Defined Functions

Unit 7. Functions. Need of User Defined Functions Unit 7 Functions Functions are the building blocks where every program activity occurs. They are self contained program segments that carry out some specific, well defined task. Every C program must have

More information

Bil 104 Intiroduction To Scientific And Engineering Computing. Lecture 7

Bil 104 Intiroduction To Scientific And Engineering Computing. Lecture 7 Strings and Clases BIL104E: Introduction to Scientific and Engineering Computing Lecture 7 Manipulating Strings Scope and Storage Classes in C Strings Declaring a string The length of a string Copying

More information

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto Ricardo Rocha Department of Computer Science Faculty of Sciences University of Porto Adapted from the slides Revisões sobre Programação em C, Sérgio Crisóstomo Compilation #include int main()

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

Scheme G. Sample Test Paper-I. Course Name : Computer Engineering Group Course Code : CO/CD/CM/CW/IF Semester : Second Subject Tile : Programming in C

Scheme G. Sample Test Paper-I. Course Name : Computer Engineering Group Course Code : CO/CD/CM/CW/IF Semester : Second Subject Tile : Programming in C Sample Test Paper-I Marks : 25 Time:1 Hrs. Q1. Attempt any THREE 09 Marks a) State four relational operators with meaning. b) State the use of break statement. c) What is constant? Give any two examples.

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

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

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,

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 & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary GATE- 2016-17 Postal Correspondence 1 C-Programming Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts, Analysis

More information

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

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

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

More information

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

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

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

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this

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

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

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

Computer System and programming in C

Computer System and programming in C 1 Basic Data Types Integral Types Integers are stored in various sizes. They can be signed or unsigned. Example Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign bit. If the sign

More information

UNIT 3 FUNCTIONS AND ARRAYS

UNIT 3 FUNCTIONS AND ARRAYS UNIT 3 FUNCTIONS AND ARRAYS Functions Function definitions and Prototypes Calling Functions Accessing functions Passing arguments to a function - Storage Classes Scope rules Arrays Defining an array processing

More information

P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS 1 ST INTERNAL ASSESMENT TEST (SCEME AND SOLUTIONS)

P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS 1 ST INTERNAL ASSESMENT TEST (SCEME AND SOLUTIONS) FACULTY: Ms. Saritha P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS 1 ST INTERNAL ASSESMENT TEST (SCEME AND SOLUTIONS) SUBJECT / CODE: Programming in C and Data Structures- 15PCD13 What is token?

More information

CSCI 171 Chapter Outlines

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

More information

PROGRAMMING IN C AND C++:

PROGRAMMING IN C AND C++: PROGRAMMING IN C AND C++: Week 1 1. Introductions 2. Using Dos commands, make a directory: C:\users\YearOfJoining\Sectionx\USERNAME\CS101 3. Getting started with Visual C++. 4. Write a program to print

More information

These are reserved words of the C language. For example int, float, if, else, for, while etc.

These are reserved words of the C language. For example int, float, if, else, for, while etc. Tokens in C Keywords These are reserved words of the C language. For example int, float, if, else, for, while etc. Identifiers An Identifier is a sequence of letters and digits, but must start with a letter.

More 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

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

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

More information

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

BASIC ELEMENTS OF A COMPUTER PROGRAM

BASIC ELEMENTS OF A COMPUTER PROGRAM BASIC ELEMENTS OF A COMPUTER PROGRAM CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING LOGO Contents 1 Identifier 2 3 Rules for naming and declaring data variables Basic data types 4 Arithmetic operators

More information

Introduction to string

Introduction to string 1 Introduction to string String is a sequence of characters enclosed in double quotes. Normally, it is used for storing data like name, address, city etc. ASCII code is internally used to represent string

More information

Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic

More information

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

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 INTERNAL ASSESSMENT TEST 1 SOLUTION PART 1 1 a Define algorithm. Write an algorithm to find sum and average of three numbers. 4 An Algorithm is a step by step procedure to solve a given problem in finite

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

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

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

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

2. Numbers In, Numbers Out

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

More information

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

Chapter 5. Section 5.1 Introduction to Strings. CS 50 Hathairat Rattanasook

Chapter 5. Section 5.1 Introduction to Strings. CS 50 Hathairat Rattanasook Chapter 5 Section 5.1 Introduction to Strings CS 50 Hathairat Rattanasook "Strings" In computer science a string is a sequence of characters from the underlying character set. In C a string is a sequence

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

Computers Programming Course 5. Iulian Năstac

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

More information

C programming basics T3-1 -

C programming basics T3-1 - C programming basics T3-1 - Outline 1. Introduction 2. Basic concepts 3. Functions 4. Data types 5. Control structures 6. Arrays and pointers 7. File management T3-2 - 3.1: Introduction T3-3 - Review of

More information

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0)

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0) CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0) Class Teacher: Pralay Mitra Department of Computer Science and Engineering Indian Institute of Technology Kharagpur A complete C program

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

ET156 Introduction to C Programming

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

More information

Course Title: C Programming Full Marks: Course no: CSC110 Pass Marks: Nature of course: Theory + Lab Credit hours: 3

Course Title: C Programming Full Marks: Course no: CSC110 Pass Marks: Nature of course: Theory + Lab Credit hours: 3 Detailed Syllabus : Course Title: C Programming Full Marks: 60+20+20 Course no: CSC110 Pass Marks: 24+8+8 Nature of course: Theory + Lab Credit hours: 3 Course Description: This course covers the concepts

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

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

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette COMP 250: Java Programming I Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette Variables and types [Downey Ch 2] Variable: temporary storage location in memory.

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

Kadi Sarva Vishwavidyalaya, Gandhinagar

Kadi Sarva Vishwavidyalaya, Gandhinagar Kadi Sarva Vishwavidyalaya, Gandhinagar MASTERS OF COMPUTER APPLICATION (MCA) Semester I (First Year) Subject: MCA-101 Programming for Logic Building (LDPL) SUB Teaching scheme Examination scheme Total

More information

Chapter 1 & 2 Introduction to C Language

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

More information

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

Procedural Programming & Fundamentals of Programming

Procedural Programming & Fundamentals of Programming Procedural Programming & Fundamentals of Programming Exercise 3 (SS 2018) 29.05.2018 What will I learn in the 4. exercise Pointer (and a little bit about memory allocation) Structure Strings and String

More information

Q1. Multiple Choice Questions

Q1. Multiple Choice Questions Rayat Shikshan Sanstha s S. M. Joshi College, Hadapsar Pune-28 F.Y.B.C.A(Science) Basic C Programing QUESTION BANK Q1. Multiple Choice Questions 1. Diagramatic or symbolic representation of an algorithm

More information

Approximately a Final Exam CPSC 206

Approximately a Final Exam CPSC 206 Approximately a Final Exam CPSC 206 Sometime in History based on Kelley & Pohl Last name, First Name Last 4 digits of ID Write your section number: All parts of this exam are required unless plainly and

More information

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

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

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

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

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

More information

CPS 101 Introduction to Computational Science

CPS 101 Introduction to Computational Science CPS 101 Introduction to Computational Science Wensheng Shen Department of Computational Science SUNY Brockport Chapter 10: Program in C Why C language: C is the language which can be used for both system

More information

Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 5, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

Computers Programming Course 10. Iulian Năstac

Computers Programming Course 10. Iulian Năstac Computers Programming Course 10 Iulian Năstac Recap from previous course 5. Values returned by a function A return statement causes execution to leave the current subroutine and resume at the point in

More information

What is recursion. WAP to find sum of n natural numbers using recursion (5)

What is recursion. WAP to find sum of n natural numbers using recursion (5) DEC 2014 Q1 a What is recursion. WAP to find sum of n natural numbers using recursion (5) Recursion is a phenomenon in which a function calls itself. A function which calls itself is called recursive function.

More information

Introduction to C Language (M3-R )

Introduction to C Language (M3-R ) Introduction to C Language (M3-R4-01-18) 1. Each question below gives a multiple choice of answers. Choose the most appropriate one and enter in OMR answer sheet supplied with the question paper, following

More information

Work relative to other classes

Work relative to other classes Work relative to other classes 1 Hours/week on projects 2 C BOOTCAMP DAY 1 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Overview C: A language

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Introduction to the C language Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) The C language

More information

SUMMER 13 EXAMINATION Model Answer

SUMMER 13 EXAMINATION 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

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

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

More information

Week 3 Lecture 2. Types Constants and Variables

Week 3 Lecture 2. Types Constants and Variables Lecture 2 Types Constants and Variables Types Computers store bits: strings of 0s and 1s Types define how bits are interpreted They can be integers (whole numbers): 1, 2, 3 They can be characters 'a',

More information

CHAPTER 4 FUNCTIONS. 4.1 Introduction

CHAPTER 4 FUNCTIONS. 4.1 Introduction CHAPTER 4 FUNCTIONS 4.1 Introduction Functions are the building blocks of C++ programs. Functions are also the executable segments in a program. The starting point for the execution of a program is main

More information

Zheng-Liang Lu Java Programming 45 / 79

Zheng-Liang Lu Java Programming 45 / 79 1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 45 / 79 Example Given a radius

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

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

2. Numbers In, Numbers Out

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

More information

A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called.

A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called. Chapter-12 FUNCTIONS Introduction A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called. Types of functions There are two types

More information

Programming. C++ Basics

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

More information

CSE101-Lec#17. Arrays. (Arrays and Functions) Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU. LPU CSE101 C Programming

CSE101-Lec#17. Arrays. (Arrays and Functions) Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU. LPU CSE101 C Programming Arrays CSE101-Lec#17 (Arrays and Functions) Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU Outline To declare an array To initialize an array To pass an array to a function Arrays Introduction

More information

C introduction: part 1

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

More information

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

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

More information

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

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

More information

BİL200 TUTORIAL-EXERCISES Objective:

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

More information