COL 100 Introduction to Programming- MINOR 1 IIT Jammu

Similar documents
Pointers and Structure. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Stamp / Signature of the Invigilator

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

COMP 2001/2401 Test #1 [out of 80 marks]

Practice Sheet #07 with Solutions

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

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

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

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

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

Programming Language A

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

Chapter Two MIPS Arithmetic

Name Roll No. Section

Precedence and Associativity Table. % specifiers in ANSI C: String Control Codes:

Materials covered in this lecture are: A. Completing Ch. 2 Objectives: Example of 6 steps (RCMACT) for solving a problem.

ME 172. Lecture 2. Data Types and Modifier 3/7/2011. variables scanf() printf() Basic data types are. Modifiers. char int float double

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

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

Lab Session # 1 Introduction to C Language. ALQUDS University Department of Computer Engineering

Procedural Programming

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

Introduction to C. Systems Programming Concepts

1/25/2018. ECE 220: Computer Systems & Programming. Write Output Using printf. Use Backslash to Include Special ASCII Characters

Subject: Fundamental of Computer Programming 2068

Programming Language A

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

Have the same meaning as variables in algebra Single alphabetic character Each variable needs an identifier that distinguishes it from the others a =

Programming Language A

.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar..

Programming Language B

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

Quiz1 Fall 2007 October 2 nd, UNIVERSITY OF WINDSOR Fall 2007 QUIZ # 1 Solution. Examiner:Ritu Chaturvedi Dated :October 2nd, 2007.

Functions. Arash Rafiey. September 26, 2017

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

Online Judge and C. Roy Chan. January 12, Outline Information Online Judge Introduction to C. CSC2100B Data Structures Tutorial 1

Computer System and programming in C

Creating, Compiling and Executing

Slides adopted from T. Ferguson Spring 2016

Basic Assignment and Arithmetic Operators

'C' Programming Language

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

Assignment 6. Q1. Create a database of students using structures, where in each entry of the database will have the following fields:

Computer Programing. for Physicists [SCPY204] Class 02: 25 Jan 2018

C and Programming Basics

Presented By : Gaurav Juneja

Programming in C and Data Structures [15PCD13/23] 1. PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme]

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

Dynamic Memory Allocation and Command-line Arguments

Computer Systems C S Cynthia Lee

UIC. C Programming Primer. Bharathidasan University

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

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

Question 4: a. We want to store a binary encoding of the 150 original Pokemon. How many bits do we need to use?

UNIVERSITY OF WINDSOR Winter 2007 QUIZ # 1 Solution. Examiner:Ritu Chaturvedi Dated : Feb 7 th, Student Name: Student Number:

Programming Language B

Variation of Pointers

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

CS 108 Computing Fundamentals. October/November Array Bootcamp

Slides adopted from T. Ferguson Spring 2016

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

Data Types and Variables in C language

IV Unit Second Part STRUCTURES

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

Programming in C++ 4. The lexical basis of C++

Computer Programming. Decision Making (2) Loops

ME 172. Sourav Saha. Md. Mahamudul Hossain Kazi Fazle Rabbi Saddam Hossain Joy Kamruzzaman Lecturer,Dept. of ME,BUET

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

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

Syntax and Variables

Pointers, Arrays, and Strings. CS449 Spring 2016

More Arrays. Last updated 2/6/19

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

University of Maryland College Park Dept of Computer Science CMSC106 Fall 2016 Midterm I

Chapter 2 (Dynamic variable (i.e. pointer), Static variable)

CS61c Midterm Review (fa06) Number representation and Floating points From your friendly reader

Variables and literals

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

Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur Number Representation

PDS Lab Section 16 Autumn Tutorial 3. C Programming Constructs

16.216: ECE Application Programming Fall 2011

Structured programming

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

Flowchart, Types, and Values

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

Computer Programming: Skills & Concepts (CP) Variables and ints

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

COMP1917 Computing 1 Written Exam Sample Questions

Programming in C Quick Start! Biostatistics 615 Lecture 4

Arithmetic Expressions in C

Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location What to bring:

Lecture 6. Statements

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

printf( Please enter another number: ); scanf( %d, &num2);

9/10/2016. Time for Some Detailed Examples. ECE 120: Introduction to Computing. Let s See How This Loop Works. One Statement/Step at a Time

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

The Compilation Process

provided. Use any other space for rough work. The question paper has total 8 pages. Rough Work

Outline. Briefly review the last class Pointers and Structs Memory allocation Linked lists

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

Transcription:

COL 100 Introduction to Programming- MINOR 1 IIT Jammu Time 1 Hr Max Marks 40 03.09.2016 NOTE: THERE 4 QUESTIONS IN ALL NOTE: 1. Do all the questions. 2. Write your name, entry number and group in all the sheets. 3. Use back side for rough work Q1 (10 marks) Q2 (7 marks) Q3 (8 marks) Q4 (10 marks) Q5 (5 marks) Total (40) 1. (10 marks) Do the following: a. Add 18 and -65 using a 8-bit 2's complement representation. (3 marks) Rough work ANSWER: 1 1 0 1 0 0 0 1 = -47 18 = 0 0 0 1 0 0 1 0 (mark 1) 65 = 0 1 0 0 0 0 0 1-65 = 1 0 1 1 1 1 1 1 (2's complement) (mark 1) 18 + (-65) = 1 1 0 1 0 0 0 1 (Negative number) = 0 0 1 0 1 1 1 1 (2's complement) (mark 1) = - 47 b. Convert the (234.25) 10 to its corresponding base 8 number. (3 marks) ANSWER: (234.25) 10 = (352.2) 8 (234) 10 = (352) 8 (mark 2) (.25) 10 = (.2) 8 (mark 1) c. Represent the fixed point real number (- 234.25) 10 using floating point representation in a 24-bit word machine, where 17 bits are used for mantissa to be represented in hexadecimal system and 7 bits are for exponent (including sign bits). State the maximum value of floating point real number stored in such system. (4 marks) ANSWER: 0 0 0 0 0 1 0 1 1 1 1 0 1 0 1 0 0 1 0 0 0 0 0 0 sign --------2---------------------- sign ------E------------- -------A------------ -----4-------------- -----0-------------- (- 234.25) 10 = (-EA.4) 16 = (-0.EA4 x 16 2 ) (mark 2) (mark 1) (mark 1) for representation 1

2. (7 Marks) Consider the following C program and write the output in the space provided. Show the working in rough space Rough work #include <stdio.h> main() { int i, j, x ; int c[10] = {1,2,3,4,5,6,7,8,9,0; int find (int x, int y) { return ( ( x < y )? 0 : x-y); void fun(int n) { int i, x=0; for (i=0; i < n; i++) { x+=i; //--------------------------------------------------------------------------------------- i=8; j=5; x=0; if ((5* (++i) +j) > 20) { x = x+ (--i)* j; Value of x = 40 { x = 7* (--j) % 6; (mark 1) Value of 5* ++i +j = 50; i = 8; j= 5; x+ (--i)* j = 40 Value of x= 40 //----------------------------------------------------------------------------------------- i=0; x=0; while (i < 5) { j= 0; while (j < i) { x += (i + j - 1); ++j; (mark 1) i++; Value of i, j = 1 1 Value of i, j = 2 1 Value of i, j = 2 2 Value of i, j = 3 1 Value of i, j = 3 2 Value of i, j = 3 3 Value of i, j = 4 1 Value of i, j = 4 2 Value of i, j = 4 3 Value of i, j = 4 4 Value of x = 30 Value of x = 30 2

//------------------------------------------------------------------------------------------- x=0; for (i=0; i < 10; ++i) if ((c[i] % 2) == 0) { x += c[i]; i+=2; (mark 2) Print the value of i, c[i] = 0 1 Print the value of i, c[i] = 1 2 Value of x = 2 Value of i = 3 Print the value of i, c[i] = 4 5 Print the value of i, c[i] = 5 6 Value of i = 7 Print the value of i, c[i] = 8 9 Print the value of i, c[i] = 9 0 Value of i = 11 //------------------------------------------------------------------ i=4; j= 5; x = find(i, find(i, j)); Value of x = 4 (mark 1) find(4, 5) = 0 x = find(i, find(i, j)) = find(4, 0) = 4; Value of x = 4 //---------------------------------------------------------------------------------------------- fun(9); Value of x = 36 (mark 2) Function 'fun' is adding integers from 1 to 8 Value of i and x = 0 0 Value of i and x = 1 1 Value of i and x = 2 3 Value of i and x = 3 6 Value of i and x = 4 10 Value of i and x = 5 15 Value of i and x = 6 21 Value of i and x = 7 28 Value of i and x = 8 36 Value of x = 36 //----------------------------------------------------------------------------------------------- 3

3. (8 marks) a. Write set of C statements to swap the values of two variables X and Y. You are not allowed to use any extra variable. (2 marks) x = x + y; y = x - y; (mark 2) x = x - y; b. Define a structure in C named 'Student' which contains four fields as { name, age, sex, department. Declare a variable as your name of 'struct Student'. Assign the values for your structure. (3 marks) struct Student (mark 2) { char name[15]; float age; char sex; char dept[25]; st1; struct Student st2 = {"Ayush", 17.5, 'm', "Computer Science"; (mark 1) c. Write an algorithm to compute your age as on today (3/Sept/2016) in terms of days, months, years. Input your age in day, month and year. Assume each month has 30 days for simplicity. (3 marks) input day, month, year; today_d =3; (mark 1/2) today_m =9; today_y =2016; if (day < today_d) then age_d = today_d - day { age_d = today_d+30 - day; (mark 1) today_m = today_m - 1 if (month < today_m) then age_m = today_m - month { age_m = today_m+12 - month; (mark 1) today_y = today_y - 1 age_y = today_y - year Output age_d, age_m, age_y; (mark 1/2) 4

4. (10 marks) a. Design an interactive command line calculator in C which will give options to the user for asking numbers and operations on it. Use switch-case to implement. Here is a sample output of the interface: $./a.out Please enter two numbers: 3 5 Please select the operation number you want to perform: 1 - add 2 - sub 3 - mul 4 - mod 1 Result is: 8 #include <stdio.h> main() { int a, b, x, result; (mark 4) scanf("input the values of two operands%d%d\n", &a, &b); scanf("input digit for operation\n%d", &x); switch (x) { case 1: result = a+b; break; case 2: result = a-b; break; (mark 5) case 3: result = a*b; break; case 4: result = a%b; break; printf("the result is: %d\n", result); (mark 1) 5. (5 marks) Write an algorithm which takes a positive integer as input, and prints which powers of 2 does the number lie between. For example, the number 269 lies between 28 (256) and 29 (512). If the input is 269, the output should be 8 9. Borderline cases which are powers of 2, such as 256, should be aligned to the lower limit of the desired range output, ie. 28 (256) and 29 (512). input num; quot = num; while (quot > 0) { quot = quot / 2; i = i+1; ; j = i-1; output( i-1, i) #include<stdio.h> main () { int num,quot,i=0 ; printf("input the value of num\n"); scanf("%d", &num); quot = num; while (quot > 0) { quot = quot / 2; i++; ; printf("%d %d", i-1, i); 5