Solution Set(Reference Book - Programming with c By Byron Gottfried Thrid Edition)

Similar documents
Subject: Fundamental of Computer Programming 2068

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

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

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

UNIT - V STRUCTURES AND UNIONS

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

Pointers and scanf() Steven R. Bagley

VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANGULATHUR

TEST BDA24202 / BTI10202 COMPUTER PROGRAMMING May 2013

A3-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH 'C' LANGUAGE

CSCI 171 Chapter Outlines

Tribhuvan University Institute of Science and Technology 2065

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

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

Operators and Expressions:

PESIT Bangalore South Campus Hosur Road (1km before Electronic City), Bengaluru Department of Basic Science and Humanities

Introduction to C Language (M3-R )

PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE

P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS DEPARTMENT OF SCIENCE AND HUMANITIES EVEN SEMESTER FEB 2017

APSC 160 Review. CPSC 259: Data Structures and Algorithms for Electrical Engineers. Hassan Khosravi Borrowing many questions from Ed Knorr

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

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

MCA Semester 1. MC0061 Computer Programming C Language 4 Credits Assignment: Set 1 (40 Marks)

PDS Lab Section 16 Autumn Tutorial 3. C Programming Constructs

Pointers (part 1) What are pointers? EECS We have seen pointers before. scanf( %f, &inches );! 25 September 2017

Computers Programming Course 5. Iulian Năstac

Dynamic Memory Allocation

Q 1. Attempt any TEN of the following:

Reg. No. : Question Paper Code : B.E./B.Tech. DEGREE EXAMINATION, JANUARY First Semester GE 6151 COMPUTER PROGRAMMING

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

(i) Describe in detail about the classification of computers with their features and limitations(10)

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

MTH 307/417/515 Final Exam Solutions

Sample Paper - II Subject Computer Science

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Procedural programming with C

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

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

Functions. Arash Rafiey. September 26, 2017

SRI VIDYA COLLEGE OF ENGINEERING & TECHNOLOGY, VIRUDHUNAGAR Department of CSE & IT Internal Test I

M1-R4: Programing and Problem Solving using C (JULY 2018)

C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS

Functions. Introduction :

EL6483: Brief Overview of C Programming Language

PERIYAR CENTENARY POLYTECHNIC COLLEGE Periyar Nagar- Vallam Thanjavur

IMPORTANT QUESTIONS IN C FOR THE INTERVIEW

Unit 3 Decision making, Looping and Arrays

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

MODULE 5: Pointers, Preprocessor Directives and Data Structures

IV Unit Second Part STRUCTURES

Pointer in C SHARDA UNIVERSITY. Presented By: Pushpendra K. Rajput Assistant Professor

Government Polytechnic Muzaffarpur.

Actually, C provides another type of variable which allows us to do just that. These are called dynamic variables.

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

Tutorial No. 2 - Solution (Overview of C)

Engineering 12 - Spring, 1999

COMPUTER APPLICATION

Programming and Data Structure Solved. MCQs- Part 2

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

Object Oriented Programming Using C++ Mathematics & Computing IET, Katunayake

C Programming Multiple. Choice

MODULE V: POINTERS & PREPROCESSORS

INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Stamp / Signature of the Invigilator

Flow Chart. The diagrammatic representation shows a solution to a given problem.

Chapter - 2 Complexity of Algorithms for Iterative Solution of Non-Linear Equations

'C' Programming Language

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

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

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

CS201 - Introduction to Programming Glossary By

Downloaded from

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

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above


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

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


Lectures 5-6: Introduction to C

AE52/AC52/AT52 C & Data Structures JUNE 2014

Advanced C Programming and Introduction to Data Structures


OBJECTIVE QUESTIONS: Choose the correct alternative:

Darshan Institute of Engineering & Technology for Diploma Studies Unit 5

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

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:

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

From Java to C. Thanks to Randal E. Bryant and David R. O'Hallaron (Carnegie-Mellon University) for providing the basis for these slides

JTSK Programming in C II C-Lab II. Lecture 3 & 4

VARIABLES AND CONSTANTS

DC54 DATA STRUCTURES DEC 2014

C PROGRAMMING. Prof. (Dr.) S. N. Mishra (Prof. & Head, Dept. of CSEA, IGIT, Sarang)

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

Algorithms & Data Structures

For Solved Question Papers of UGC-NET/GATE/SET/PGCET in Computer Science, visit

Department of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #07. Topic: Pointer in C Date:

Decision Making and Loops

Short Notes of CS201

Arrays and Pointers (part 1)

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

Name :. Roll No. :... Invigilator s Signature : INTRODUCTION TO PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

Transcription:

(2½ Hours) [Total Marks: 75 N. B.: (1) All questions are compulsory. (2) Make suitable assumptions wherever necessary and state the assumptions made. (3) Answers to the same question must be written together. (4) Numbers to the right indicate marks. (5) Draw neat labeled diagrams wherever necessary. (6) Use of Non-programmable calculators is allowed. Solution Set(Reference Book - Programming with c By Byron Gottfried Thrid Edition) 1. Attempt any three of the following: a. List various techniques for the development of a program? Explain any one with suitable example.(pg 1.10-1.6) Program writing is a systematic process. It is not all about coding only. It requires a certain methodology. Threre are three commonly used representation for the development of a program as given below: 1.Algorithm 2.Pseudo-code 3. Flow chart Any one of the above can be explained with example. b. What is program development life cycle? Explain its various stages. Page 1.12-1.7 Programmer for developing a program can not directly start any program or project. Programmer has to understand whole program or project. He should analyse the sequence and flow of the program. Following are the steps in program development life cycle. 1. Understand the problem 2. plan the logic 3. code the program 4. use software 5. Program Testing 6. Put the program into production 7. Maintain the program Explanation of all the above points should be given. c. Discuss desirable program characteristics. (pg 1.21-1.12) Explanation of following points should be given Integrity Clarity Simplicity Efficiency Modularity Generality d. Define keywords and identifiers in C language? Also differentiate between keywords and identifiers. Page 2.3

e. What is a constant? List various constants in C. Explain any two in detail with suitable examples. Page 2.12-2.8 f. Assume that your version of c can recognize only first eight characters of an identifier name, though identifier names may be arbitrarily long. Which of the following pairs of identifier names are considered to be identical and which are distinct? (i) Address, address (ii) name, names (iii) list1, list2 (iv) answer, ANSWER (v) identifier_1, identifier_2 Ans. (i) Distinct (ii) Distinct (iii) Distinct (iv)distinct (v) Identical 2. Attempt any three of the following: 15 a. What do you understand from hierarchy/precedence of operators? What is the hierarchy of operators in c? Ans. Chapter-3, Page 3.17-3.1 The order in which various operators are executed is known as hierarchy or precedence of operators. Order of execution of operators should be written in tabular form. b. Explain the purpose and use of following operators with suitable examples (i) == and = (ii) Conditional operator (? :) Ans. Chapter3, Page 3.13 3.4, Page 3.10-3.3 Page 3.16 3.5 c. A c program contains the following declarations and initial assignments int i=8, j=5; float x=0.005, y=-0.01; Determine the value of each of the following expressions (i) 2*(i/5)+(4*(j-3)) % (i+j-2) (ii) (x>y)&&(i>0) (j<5); Ans. (i) 10 (ii) 1 d. Summarize the meaning of commonly used conversion characters within the control string of a scanf() function. Ans. Chapter 4, Page 4.4-4.4 (minimum four conversion characters should be explained) e. A c program contains the following variable declarations float a=2.5, b=0.0005, c= 3000.; Show the output from following printf statements (i) printf( %f %f %f,a,b,c); (ii) printf( %3f %3f %3f,a,b,c); (iii) printf( %8f %8f %8f,a,b,c); (iv) printf( %8.4 f %8.4f %8.4f,a,b,c); (v) printf( %e %e %e,a,b,c); Ans. (i)2.500000 0.000500 3000.000000 (ii)2.500000 0.000500 3000.000000 (iii) 2.500000 0.000500 3000.000000 (iv) 2.5000 0.0005 3000.0000 (v)2.500000e+000 5.000000e-004 3.000000e+003 f. Write an interactive c program to find roots of a quadratic equation ax 2 +bx+c=0 and roots are given by -b± (b 2-4c)/2a. //Find roots of a quadratic equation

#include<stdio.h> #include<math.h> float a,b,c,root1,root2,d, printf( \nenter value of a: ); scanf( %f,&a); printf( \nenter value of b: ); scanf( %f,&b); printf( /nenter value of c: ); scanf( %f,&c); D=b*b-4*a*c; If(D==0) Root1=-b/(2*a); Root2=Root1; printf( \nroots are equal ); printf( \nroot1=%f\troot2=%f,root1,root2); else if(d>0) Root1=(-b+sqrt(b*b -4*a*c))/(2*a); Root2=(-b-sqrt(b*b -4*a*c))/(2*a); printf( \nroots are real and distinct: ); printf( \nroot1=%f\troot2=%f,root1,root2); else Printf( \nroots are imaginary ); 3. Attempt any three of the following: 15 a. What do you understand from control statements? Explain branching, selection and looping in brief. Ans. Chapter 6- Page 5.21 b. Differentiate between while and do while loop with suitable examples. When to use which loop? Ans. Chapter6, Page6.8-6.3, 6.4 c. How many times following loops will be executed in the following codes (i)for(i=10;i<=25;i++). (ii)int i=0,n=10; while(i<=n) Sum+=i; (iii)for(i=0,j=10;i<10;i++,j--) (iv)for(i=100;i>70;i=i-2).

. (v)int i=1,n=5; while(i<=10). If(i==n) break; i++; Ans. (i) 16 (ii) infinite (iii) 10 (iv) 15 (v) 5 d. Predict the output of following c codes (i)int i; for(i=0;i<=2;i++) switch(i) case 1:printf( %d,i); case 2:printf( %d,i); default:printf( %d,i); (ii)void swap(int, int); int x=20,y=10; swap(x,y); printf( %d, %d,y,x); void swap(int x, int y) int temp; temp=x; x=y; y=temp; Ans. (i) 011122 (ii)10,20 e. What is a function? Explain the purpose of function prototype, function call and function definition in a c program. Ans. Chapter 7, page7.2,7.10 f. What is recursion? Write a recursive function to calculate factorial of a number. Ans. Chapter 7, Page7.23 4. Attempt any three of the following: 15 a What do you understand from storage classes? List various storage classes? Explain any two. Ans. Chapter 8, Page 8.1 b What is the purpose of a static function in a multifile program? Explain with suitable example. Ans. Chapter 8, Page 8.5 c What are preprocessors in c language? List various preprocessors and explain #if- #else-#endif preprocessor directive with suitable example. Ans. Chapter 15, Page 15.20-15.5 d What is a macro? Summarize the similarities and differences between macros and functions. Ans. Chapter 15, Page 15.11 e What is an array? How one dimensional arrays can be defined and accessed?

f Ans. Chapter 9 Page 8.41 Write a c program to find big number out of given n numbers stored in an array using a function. Ans. //program to find big number using function #include<stdio.h> int Max(int n,int arr[]); int n,a[100],big,i; printf( \nenter number of elements in the array(not more than 100): ); scanf( %d,n); printf( \n Enter %d elements of array: ); for(i=1;i<=n;i++) scanf( %d,&a[i]); big=max(n,a); printf( \nbig number=%d,big); int Max(int n1, int arr[]) int i,large=0; for(i=1;i<=n1;i++) if(arr[i]>large) large=arr[i]; return large; 5. Attempt any three of the following: 15 a. A c program contains following statements int i, j=25; int pi,*pj=&j; *pj=j+5; i=*pj+5; pi=pj; *pi=i+j; Suppose each integer quantity occupies 2 bytes of memory. If the value assigned to i begins at address 1456 and value assigned to j begins at 1458 then (i) What value is represented by &i and &j? (ii) What value is represented by pj and *pj? (iii) What value is assigned to i? (iv) What is the value represented by pi? (v) What value is represented by (pi+2)? Ans. (i) 1456,1458 (ii)1458,65 (iii)35 (iv)1458 (v)1462 b. What is dynamic memory allocation? Explain the use of malloc function with example. Ans. Chapter 11, Page 11.18 11.5 c. Write a c program to perform addition and subtraction of two pointer variables. Ans. //Program to perform addition and subtraction of two pointer variables

#include<stdio.h> #include<conio.h> int n1,n2,*ptr1,*ptr2,sum,sub; printf( \nenter two integers to be added or subtracted: ); scanf( %d%d,&n1,&n2); ptr1=&n1; ptr2=&n2; sum=*ptr1+*ptr2; sub=*ptr1-*ptr2; printf( \nsum=%d,sum); printf( \ndifference=%d,sub); getch(); d. What is a structure? How does a structure differ from an array? Ans. Chapter 12,Page 11.69 12.1 e. What is a union? Differentiate between structure and union? Ans. Chapter 12, Page 12.55 f. (a) Define a structure of type hms containing three integer members, called hours, minutes and second, respectively. Then define a union containing two members, each a structure of type hms. Call the union members local and home respectively. Declare a pointer variable called time that points to this union. (b) Define a union of type ans which contains an integer quantity called ians, a floating point quantity called fans, a double precision quantity called dans. Then define a structure with members a union of type ans called answer, a single character called flag, integer quantities called a and b. Finally declare two structure variables called x and Y Ans. (a) struct nms int hours; int minute; int second; union struct hms local; struct hms home; *time; (b) union ans int ians; float fans; double dans; ; struct union ans answer; char flag; int a; int b; x,y;