SHARDA UNIVERSITY SCHOOL OF ENGINEERING & TECHNOLOGY Mid Term Examination, (Odd Term, ) SOLUTION

Similar documents
Faculty: Pushpendra K Rajput Session:

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

Additional Questions

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

Computer Programming. Decision Making (2) Loops

Subject: Fundamental of Computer Programming 2068

Lecture 02 C FUNDAMENTALS

Decision Making -Branching. Class Incharge: S. Sasirekha

Functions. Arash Rafiey. September 26, 2017

The Hyderabad Public School, Begumpet, Hyderabad, A.P

Copy: IF THE PROGRAM or OUTPUT is Copied, then both will have grade zero.

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

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

Tribhuvan University Institute of Science and Technology 2065

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

Kadi Sarva Vishwavidyalaya, Gandhinagar

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

Programming for Engineers Iteration

Lab 2: Structured Program Development in C

Variables, Data Types, and Arithmetic Expressions Learning Objectives:

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

1. The keyword main in C language is used for

Sir Syed University of Engineering and Technology. Computer Programming & Problem Solving ( CPPS )

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

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

Q 1. Attempt any TEN of the following:

(Following Paper ID and Roll No. to be filled by the student in the Answer Book)

Computer System and programming in C

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

UIC. C Programming Primer. Bharathidasan University

CS1100 Introduction to Programming

Lab ACN : C++ Programming Exercises

C: How to Program. Week /Mar/05

UNIVERSITY OF WINDSOR Fall 2006 QUIZ # 1. Examiner:Ritu Chaturvedi Dated : Oct 3rd, Student Name: Student Number:

3/13/2012. ESc101: Introduction to Computers and Programming Languages

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

CCE RR REVISED & UN-REVISED KARNATAKA SECONDARY EDUCATION EXAMINATION BOARD, MALLESWARAM, BANGALORE G È.G È.G È..

Introduction. C provides two styles of flow control:

Lecture 2: C Programming Basic

Chapter 2 - Introduction to C Programming

Operators and Expressions:

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

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

Multiple Choice Questions ( 1 mark)

Overview of C, Part 2. CSE 130: Introduction to Programming in C Stony Brook University

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

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

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

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

Computers Programming Course 6. Iulian Năstac

Operators & Expressions

Division. Reverse Box Method

BRANCHING if-else statements

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

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

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

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Data Types and Variables in C language

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

Q1 Q2 Q3 Q4 Q5 Total 1 * 7 1 * 5 20 * * Final marks Marks First Question

15 FUNCTIONS IN C 15.1 INTRODUCTION

Computers Programming Course 5. Iulian Năstac

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

Chapter 2: Overview of C. Problem Solving & Program Design in C

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

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

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

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

Syllabus of Diploma Engineering. Computer Engineering. Semester: II. Subject Name: Computer Programming. Subject Code: 09CE1104

Unit-2 (Operators) ANAND KR.SRIVASTAVA

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

UNIT IV INTRODUCTION TO C

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Essar Placement Paper

Number Theory and Proof Methods

Data types, variables, constants

MA 511: Computer Programming Lecture 2: Partha Sarathi Mandal

What we have learned so far

Informatics Ingeniería en Electrónica y Automática Industrial

Department of Computer Applications

LAB 2.1 INTRODUCTION TO C PROGRAMMING

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

Computer Programming & Problem Solving ( CPPS ) Turbo C Programming For The PC (Revised Edition ) By Robert Lafore

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

Chapter 3 Structure of a C Program

C Programming Class I

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:

Course Outline Introduction to C-Programming

CPE 101. Overview. Programming vs. Cooking. Key Definitions/Concepts B-1

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

AMCAT Automata Coding Sample Questions And Answers

Introduction to Java Applications

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Expression and Operator

Computer Science 217 Final Exam May 15, :30pm-4:30pm

MA 511: Computer Programming Lecture 3: Partha Sarathi Mandal

Transcription:

SHARDA UNIVERSITY SCHOOL OF ENGINEERING & TECHNOLOGY Mid Term Examination, (Odd Term, 2016-17) SOLUTION Program: B. Tech. Branch: All Term:I Subject: Logic Building and Problem Solving Using C Paper Code: CSE110 Date: Shift: Time: M.M: 20 Note: (i) No student will leave the room till end of the examination. (ii) Attempt all questions. SECTION A Q.1 Attempt any FOUR questions in this section: (i) Why we require a translator in any programming language? Discuss various types of translators available for computer languages. Programming means giving some instructions to the computer by a programmer to achieve a particular task. In this process two objects are communicating; (1) Computer that knows only machine language i.e. everything in the form of computer, (2) Programmer that knows a programming language in which most of the words have been taken from English i.e. English like language. To make conversation possible we need a third object (translator) having knowledge of both the language. Translators are as follows. i. Assembler ii. Compiler iii. Interpreter Assembler: An assembler translates the symbolic codes of programs of an assembly language into machine language instructions Compiler: A compiler searches all the errors of a program and lists them. If the program is error free then it converts the code of program into machine code and then the program can be executed by separate commands. Interpreter: An interpreter checks the errors of a program statement by statement. After checking one statement, it converts that statement into machine code and then executes that statement. The process continues until the last statement of program occurs. (ii) What would be the output of following C programs a)void main(){ int i=2,j=3,k,l; float a,b; k = i / j * j ; l = j / i * i ; a = i / j * j ; b = j / i * i ; printf("%d %d %f %f",k,l,a,b); OUTPUT b) void main(){ int a=4,b=3,c=2,d; float w=1.5,x=2.5,y=3.5,z; d = a + b /(w+c) * x - y; z = c/a % b + x *a / y w; printf( d=%d ; z=%f,d,z); OUTPUT

(iii) Write a program in C to add two distances given in kilometers and meters. #include<stdio.h> #include<conio.h> void main() { //Variable declaration part int km1,m1,km2,m2,km3,m3,convertedkm; //receive input from user printf( Enter first distance (Kilometer and Meter):\n ); scanf( %d%d,&km1,&m1); printf( Enter second distance (Kilometer and Meter):\n ); scanf( %d%d,&km2,&m2); //calculate sum m3 = m1 + m2; convertedkm = m3/1000; m3 = m3 % 1000; km3 = km1 + km2 + convertedkm; //print output printf( Distance1:\t%d\t%d\n,km1,m1); printf( Distance2:\t%d\t%d\n,km2,m2); printf( ------------------------------------- ); printf( Distance3:\t%d\t%d,km3,m3); (iv) Write an algorithm to convert number of seconds into equivalent Hours minutes and seconds. INPUT: Number of Seconds OUTPUT: equivalent time in Hours:Minutes: Seconds ALGORITHM: 1. Start 2. Take number of seconds from user, N_S 3. Calculate Hours = N_S / 3600 4. Calculate R_S = N_S % 3600 5. Calculate Minutes = R_S / 60 6. Calculate Seconds = R_S % 60 7. Print Hours:Minutes:Seconds 8. End

(v) What is a data type in C? Discuss all basic data types available in C along with their modifiers. A data type defines a set of values and the operations that can be performed on them with size required in memory. C provides the programmer with FIVE basic data types These are: integer character float double void Modifying the Basic Types Except for type void, the basic data types may have various modifiers preceding them. You use a modifier to alter the meaning of the base type to fit various situations more precisely. The list of modifiers is shown here: signed unsigned long short You can apply the modifiers signed, short, long, and unsigned to integer base types. You can apply unsigned and signed to characters. You may also apply long to double. SECTION B Q.2 Attempt any TWO questions in this section: (i) Write an algorithm to find if the reverse of a number is equals to it or not. (Assume that number is having 5 digits) INPUT: A Five Digit Number OUTPUT: Yes, if given number and its reverse is equal, No otherwise ALGORITHM: 1. Start 2. Take a Five Digit Number, N //separate each digit from the number 3. Calculate D1 = N % 10 //first digit 4. Calculate N = (N D1) / 10 5. Calculate D2 = N % 10 //second digit 6. Calculate N = (N D2) / 10 7. Calculate D3 = N % 10 //third digit 8. Calculate N = (N D3) / 10 9. Calculate D4 = N % 10 //fourth digit 10. Calculate N = (N D4) / 10 11. Calculate D5 = N % 10 //fifth digit //calculate reverse of the number 12. Calculate Rev_N = D1*10000 + D2*1000 + D3*100 + D4*10 + D5 13. If N == Rev_N then GOTO Step 14 Else GOTO step 15 14. Print YES GOTO 16 15. Print NO 16. End

(ii) Draw a flow chart that receives two integers A and B and performs following operations: a) If A is greater than B and divisible by B then print quotient of A/B. b) If A is greater than B and not divisible by B then print remainder of A/B. c) If B is greater than A then calculate and print A*B d) If A and B are equal print a message There is a tie! (iii) Solve the following number conversion: a) (ABC.D) 15 = (? ) 13 c) (125.45) 11 = (? ) 9 (ABC.D) 15 = ( 2427.8666 ) 10 = ( 1149.B35B ) 13 (125.45) 11 = (148.4049 ) 10 = ( 174.3571 ) 9 b) (246) 8 = (? ) 16 d) (FFF.AA) 16 = (? ) 8 (246) 8 = ( 166 ) 10 = ( A6 ) 16 (FFF.AA) 16 = ( 4095.664 ) 10 = (7777.5244 ) 8

SECTION C Q. 3 Draw a flow chart and write a program in C that will add 5 in each digit of a 4 digit number and map it between 0 and 4 according to following mapping: Calculated Digit 5 6 7 8 9 10 11 12 13 14 Mapped Digit 0 1 2 3 4 0 1 2 3 4

#include<stdio.h> #include<conio.h> void main() { //declare all required variables int Num, d1, d2, d3, d4, New_Num; //Receive input printf( Enter a Four Digit Number ); scanf( %4d,&Num); //Mapping of Digits d1 = (Num % 10 + 5) % 5; Num = (Num d1) / 10; d2 = (Num % 10 + 5) % 5; Num = (Num d2) / 10; d3 = (Num % 10 + 5) % 5; Num = (Num d3) / 10; d4 = (Num % 10 + 5) % 5; New_Num = d4*1000 + d3*100 + d2*10 +d1; //output printf( New Number (After Processing Each Digit) is: %d,new_num);