Name Roll No. Section

Similar documents
Indian Institute of Technology Kharagpur Programming and Data Structures (CS10001) Autumn : Mid-Semester Examination

IEEE 754 Floating-Point Format

Programming & Data Structure: CS Section - 1/A DO NOT POWER ON THE MACHINE

Programming and Data Structure Tutorial sheet: 1 Topics: Data Handling, Operators and Expressions, Input and Output Operations.

Make sure the version number is marked on your scantron sheet. This is Version 1

Q1 (15) Q2 (15) Q3 (15) Q4 (15) Total (60)

Q1 (15) Q2 (15) Q3 (15) Q4 (15) Total (60)

Q1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

Indian Institute of Technology, Kharagpur

INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Stamp / Signature of the Invigilator

CSC 373 Sections 501, 510 Winter 2015 C Examples

EECE.2160: ECE Application Programming Spring 2016 Exam 1 Solution

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

Programming and Data Structures

Sample Examination. Family Name:... Other Names:... Signature:... Student Number:...

Q. 1 What will be the output of the following program? Justify your answer. [4] #include <stdio.h> main(){ int i=4, a[5]={1,2,3,4,5};

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

ECE15: Introduction to Computer Programming Using the C Language. Lecture Unit 4: Flow of Control

only in the space provided. Do the rough work in the space provided for it. The question paper has total 12 pages.

Department of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #04

Principles of C and Memory Management

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

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

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

C Program Reviews 2-12

Q1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

Dr. R. Z. Khan, Associate Professor, Department of Computer Science

ECE 15 Fall 15 Final Solutions

Fundamental of Programming (C)

Fundamentals of Programming

INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Stamp / Signature of the Invigilator

INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Stamp / Signature of the Invigilator

Department of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #06

COMP1917 Computing 1 Written Exam Sample Questions

Dept. of CSE, IIT KGP

16.216: ECE Application Programming Fall 2011

Programming with Indexed Variables

CS1100 Introduction to Programming

Lecture 6. Statements

INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Stamp / Signature of the Invigilator

Structured programming

Engineering 12 - Spring, 1998

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

& Technology. Expression? Statement-x. void main() int no; scanf("%d", &no); if(no%2==0) if(no%2!=0) Syllabus for 1. of execution of statements.

1. Write a C program that receives 10 float numbers from the console and sort them in nonascending order, and prints the result

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

Question Bank (SPA SEM II)

INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Stamp / Signature of the Invigilator

Q1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

Midterm Exam. CSCI 2132: Software Development. March 4, Marks. Question 1 (10) Question 2 (10) Question 3 (10) Question 4 (10) Question 5 (5)

COL 100 Introduction to Programming- MINOR 1 IIT Jammu

DS: CS Computer Sc & Engg: IIT Kharagpur 1. roblem Set III. Goutam Biswas

Midterm Exam Answers Instructor: Randy Shepherd CSCI-UA.0201 Spring 2017

EECE.2160: ECE Application Programming Fall 2016 Exam 1 Solution

DEPARTMENT OF ELECTRICAL AND ELECTRONIC ENGINEERING PROGRAMMING TECHNIQUES I EE271

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

Formatted Input/Output

CS , Fall 2001 Exam 2

EECE.2160: ECE Application Programming Spring 2018

CS360 Midterm 1 - February 21, James S. Plank. Put all answers on the answer sheet. In all of these questions, please assume the following:

C Programming. The C Preprocessor and Some Advanced Topics. Learn More about #define. Define a macro name Create function-like macros.

Operators and expressions. (precedence and associability of operators, type conversions).

C Program. Output. Hi everyone. #include <stdio.h> main () { printf ( Hi everyone\n ); }

Indian Institute of Technology Kharagpur Programming and Data Structures (CS10001) Autumn : End-Semester Examination

Introduction to Computing Lecture 07: Repetition and Loop Statements (Part II)

Flow of Control. Selection. if statement. True and False in C False is represented by any zero value. switch

ESC 101N: Fundmentals of Computing ( IInd Semester) Mid Sem II Examination PM, Monday 7th March, 2011

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

Department of Computer Science Purdue University, West Lafayette

Q1: C input/output; operators / 46 Q2: Conditional statements / 34 Q3: While and do-while loops / 20 TOTAL SCORE / 100 Q4: EXTRA CREDIT / 10

Programming Language A

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

Week 3 More Formatted Input/Output; Arithmetic and Assignment Operators

16.216: ECE Application Programming Fall 2015 Exam 1 Solution

Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 2

16.216: ECE Application Programming Spring 2015 Exam 2 Solution

Practice Sheet #07 with Solutions

Operators and Expressions:

Structured programming. Exercises 3

Computer Programming 5th Week loops (do-while, for), Arrays, array operations, C libraries

EECE.2160: ECE Application Programming Spring 2017 Exam 1 Solution

MODULE 2: Branching and Looping

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

Welcome! COMP s1. Programming Fundamentals

Welcome! COMP s1 Lecture 7. COMP s1. Before we begin. Strings. Programming Fundamentals. Overview. Andrew Bennett

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

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

CS , Fall 2001 Exam 2

Introduction: The Unix shell and C programming

Number Systems, Scalar Types, and Input and Output

Programming and Data Structures Mid-Semester - Solutions to Sample Questions Dept. of Computer Science and Engg. IIT Kharagpur Spring

ECE 15 Fall 15 Midterm Solutions

Faculty: Pushpendra K Rajput Session:

MA 511: Computer Programming Lecture 3: Partha Sarathi Mandal

Binary Representation. Decimal Representation. Hexadecimal Representation. Binary to Hexadecimal

Decimal Representation

Learning to Program with Haiku

Introduction to Computer Science: Final Exam

Numerical Precision. Or, why my numbers aren t numbering right. 1 of 15

List of Programs: Programs: 1. Polynomial addition

Transcription:

Indian Institute of Technology, Kharagpur Computer Science and Engineering Department Class Test I, Autumn 2012-13 Programming & Data Structure (CS 11002) Full marks: 30 Feb 7, 2013 Time: 60 mins. Name Roll No. Section 1. Answer all questions in the space provided. No extra sheet will be provided. 2. First 10 questions carry 1 point each and the next 10 questions carry 2 points each. 1. PB-1 Which one of the following data types requires minimum storage space and which one requires the maximum storage space for representation? char, int, float, double min: char, max: double 2. PB-1 What will be displayed when the following program executes? #define LOW 0.9876 int x = 100*LOW; printf("low=%f, x=%d\n", LOW, x); LOW=0.987600, x=98 1 2 mark each. 3. PB-1 What will be displayed when the following program executes? int x = 1, y=2; printf("%d, %d\n", x/y*100, 100*x/y); 0, 50 1 2 mark each. 1

4. PB-1 Write the unsigned binary representation for the decimal number 7.25, clearly showing the decimal point. 111.01 If the whole part (111) is correctly written but the fractional part is incorrect, then 1 mark should be awarded. 2 5. PB-1 What will be displayed when the following program executes? int i; for (i=0; i<10; i+=3) ; printf("i=%d\n",i); 12 6. RM-1 What will be displayed when the following instruction executes: printf("%d\n", C - F ); -3 7. RM-1 How many times will the for loop of the following C program execute and what will be the output of the program? main(){ int i; for(i=10; i=20; i++) printf("%d, ",i); Infinite number of times. Output: 20, 20, 20,... 8. RM-1 The following code segment contains an error. Underline the part that is erroneous and write only that part corrected in the following blank space. 2

int a=27; int b=11; int c=35; if (a<b<c) printf("a, b, c are sorted in ascending order.\n\n"); else printf("a, b, c are not sorted in ascending order.\n"); (a<b && b<c) 9. RM-1 What will be the output produced by the following program segment? int x=2, y=17, z=11, result=5; result -= x/5 * z % 13 *y / 3 * x; printf( "%d\n", result ); 5 10. RM-1 What will be displayed after the following code segment executes? char c= r ; switch(c){ case b : printf("blue \n"); case r : printf("red \n"); case g : printf("green \n"); break; case y : printf("yellow \n"); default: printf("other \n"); Red Green 11. AB-2 What will be printed after the following code segment executes? int total=1, num=5; while (num>1) total = total * --num; printf ("%d\n", total); 24 3

12. AB-2 Write the missing part of the for statement so that the following code segment displays the same output as in the previous question (Question 11)? int total=1, num=5; for ( ) /*write the missing code*/ total = total * --num; printf ("%d\n", total); ( ; num>1; ) Extra variables should not be introduced. One may get at most 1/2 marks out of 2 if he/she uses extra vars. 13. PB-2 What will be displayed when the following program executes? int i = 1; int c = c ; while (++i<5) { c++; printf("%c-",c+i); printf("\n"); f-h-j- 1 mark if one writes fhg (hyphens monitted), 1 1 2 marks if one writes f-h-j (last hyphen omitted). 14. PB-2 The following program is to first read an integer n. Then it has to determine the highest perfect square s that does not exceed n. Fill up the missing code parts. int n, s = 1; printf("enter a +ve int: "); scanf("%d\n",&n); while ( ) { /*write the missing code*/ s++; ; /*write the missing code*/ printf("max square <= %d = %d\n\n", n, s); 4

(s*s<=n) s=(s-1)*(s-1); 1 mark for each. 15. PB-2 For the unsigned 8-bit binary number 1010 0110, write the equivalent decimal and hexadecimal numbers. 166, A6 16. RM-2 What value will be printed after the following loop executes? int i,j; for (i=j=0; i<10; i++) j = i++ + j; printf("%d\n", j); 20 17. RM-2 Consider the following code segment that is intended to compare the fractional parts of two floating point numbers (num1 and num2) and print the one having the larger fractional part. Some parts of the program segment are missing (indicated by dotted line). Fill up the indicated missing parts. float num1=12.314, num2=7.589; if ( >= ) printf("number having larger fraction is= f\n", num1); else printf("number having larger fraction is= f\n", num2); (num1-(int)num1) >= (num2-(int)num2) 18. RM-2 Determine how many times the word Here will be printed. count1 = 1; while (count1 < 10) { count2 = 2; while (count2 <= 20) { printf("here\n"); 5

count2++; count1++; 19*9=171 19. RM-2 Write down the output of the following program. #include <stdio.h> int i=3; printf("%d\n", (--i + 3)); printf("%d\n", (i++ + 10)); /* end main */ 5 and 12 1 mark each. 20. RM-2 In the following code segment, if the user enters any character other than Y or N, then the program should display: You must type Y or N (for yes or no). However, the program does not work as desired, as there is a mistake in the conditional expression of the if statement. Write the correct expression in the empty box provided. char response; printf("please enter your response Y/N (for yes or no)\n"); scanf("%c",&response); if (response!= Y response!= N ) /* please correct */ printf("you must type Y or N (for yes or no)\n");!(response == Y response == N ) or (response!= Y && response!= N ) RM, AB, PB CSE Deptt., IIT KGP 6