Week 1 Questions Question Options Answer & Explanation A. 10 B. 20 C. 21 D. 11. A. 97 B. 98 C. 99 D. a

Similar documents
C PROGRAMMING QUESTIONS AND

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

1. a) What #include statement do you put at the top of a program that does uses cin, cout or endl?

Decision Making -Branching. Class Incharge: S. Sasirekha

C Multiple Choice Questions and answers MCQ with Ans.

Technical Questions. Q 1) What are the key features in C programming language?

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

PROGRAMMING FUNDAMENTALS

NWEN 241 Systems Programming Exercises (Set 1)

Lecture 02 C FUNDAMENTALS

Q 1. Attempt any TEN of the following:

Comments. Comments: /* This is a comment */

CSCE 110 Dr. Amr Goneid Exercise Sheet (7): Exercises on Recursion (Solutions)

DECISION MAKING STATEMENTS

Solutions to Assessment

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

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

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

Operators in java Operator operands.

80 Minutes CENG 230 MidtermExam :40

SSOL Language Reference Manual

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

C PROGRAMMING LANGUAGE. POINTERS, ARRAYS, OPERATORS AND LOOP. CAAM 519, CHAPTER5

x 2 +7x+1 x<0 7x+17 0<x 10 Z= x 2 +10x x 25 25x+100 other values

Midterm Exam 1 Solutions C Programming Dr. Beeson, Spring 2009

SUMMER 13 EXAMINATION Model Answer

Operators & Expressions

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

Unit-2 (Operators) ANAND KR.SRIVASTAVA

SAMPLE QUESTIONS FOR DIPLOMA IN INFORMATION TECHNOLOGY; YEAR 1

Unit 5. Decision Making and Looping. School of Science and Technology INTRODUCTION

(2 7 *0) + (2 6 *1) + (2 5 *1) + (2 4 *0) + (2 3 *1) + (2 2 *1)+(2 1 *0)+(2 0 *1)

Government Polytechnic Muzaffarpur.

ECE 15 Fall 16 Midterm Solutions

Chapter 4: Expressions. Chapter 4. Expressions. Copyright 2008 W. W. Norton & Company. All rights reserved.

UNIT- 3 Introduction to C++

DEPARTMENT OF MATHS, MJ COLLEGE

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

CMPS 12A - Winter 2002 Final Exam A March 16, Name: ID:

BoredGames Language Reference Manual A Language for Board Games. Brandon Kessler (bpk2107) and Kristen Wise (kew2132)

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

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

DECISION CONTROL AND LOOPING STATEMENTS

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

a. ++ b. -- c. sizeof d. - e. all the above 11. Which of the following is the wrong combination for any two operators in C a. different precedence,

Unit 3 Decision making, Looping and Arrays

Flow Control. CSC215 Lecture

UIC. C Programming Primer. Bharathidasan University

Expression and Operator

Lecture 3. More About C

Data Types and Variables in C language

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

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

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

UNIT 3 FUNCTIONS AND ARRAYS

AMCAT Automata Coding Sample Questions And Answers

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

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Mechatronics and Microcontrollers. Szilárd Aradi PhD Refresh of C

Introduction. C provides two styles of flow control:

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

3 The L oop Control Structure

Language Fundamentals Summary

ME 172. C Programming Language Sessional Lecture 8

Writing Program in C Expressions and Control Structures (Selection Statements and Loops)

1. The keyword main in C language is used for

Part I Part 1 Expressions

C Functions. CS 2060 Week 4. Prof. Jonathan Ventura

Iosif Ignat, Marius Joldoș Laboratory Guide 4. Statements. STATEMENTS in C

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

Group of Institutions Test Paper: Technical (Set-4) T&P Department } (A) 0 (B) 25 (C) 1 (D) -1 (E) 2. } (A) Sachin (B) Rahul

Programming and Data Structure Solved. MCQs- Part 2

More examples for Control statements

Functions. Arash Rafiey. September 26, 2017

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

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Week 2 / Lecture 2 15 March 2017 NWEN 241 Control constructs, Functions. Alvin Valera

PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE

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

A First Program - Greeting.cpp

There are three questions on this exam. You have 2 hours to complete it. Please indent your program so that it is easy for the grader to read.

Midterm Exam 2 Solutions, C programming

Basics of Programming

공학프로그래밍언어 (PROGRAMMING LANGUAGE FOR ENGINEERS) -CONTROL FLOW : LOOP- SPRING 2015, SEON-JU AHN, CNU EE

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Lecture 5: C programming

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

ESC101N: Fundamentals of Computing End-sem st semester

Decision Making and Loops

A control structure refers to the way in which the Programmer specifies the order of executing the statements

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

JAVA Programming Fundamentals

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

2. Which of the following will print the value 2 for the above code?

Additional Questions

Prepared by: Shraddha Modi

Fundamental of Programming (C)

Fundamentals of Programming

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

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Transcription:

Sr. no. Week 1 Questions Question Options Answer & Explanation 1 Find the output: int x=10; int y; y=x++; printf("%d",x); A. 10 B. 20 C. 21 D. 11 Answer: D x++ increments the value to 11. So printf statement uses x=11. 2 Find the output: char c='a'; switch(c) case 97: printf("97"); break; case 98: printf("98"); break; case 99: printf("99"); break; default: printf("default"); A. 97 B. 98 C. 99 D. a Answer: A The ASCII value of a is 97 which gets switched while switching the char c

3 Find the output: int x=10; int a=1,b=2,c=3,d=4; x+=a=b*c+d-a; printf("%d,%d",a,x); A. 1,10 B. 9,11 C. 9,19 D. 1,19 Answer: C The expression b*c+d-a gets evaluated first, which then sets the value of a to 9. This value is used for incrementing x. 4 Find the output: float a=1.1; int b=1.1; if(a==b) printf("yes"); else printf("no"); A. YES B. NO C. Error Answer: B int b = 1.1 assigns 1 to b. Comparing a==b compares 1 with 1.1 which is FALSE. 5 Find the output: int i,x=10; for(i=0;i<2;i++); x++; printf("%d",x); 11 Answer: B The semicolon after the for loop terminates it and the brackets are treated as a single block, thus x++ is executed only once.

6 Find the output: int i=-10; if(i) printf("1"); i=0; if(i) printf("2"); i=5; if(i) printf("3"); 13 Answer: A Condition is evaluated to true for any non-zero value. So, the first and last IF conditions are evaluated as TRUE. 7 Find the output: int x=10; do x++; while(x++>12); printf("%d",x); A. 10 B. 11 C. 12 D. 13 E. The program runs for more than 10 iterations. Answer: C The do loop executes once and goes to the check. In the check, there is one more increment. So the final answer is 12. 9 Find the output: void main() A. 2 B. 3 Answer: C

int a=22; a=a>>4; printf("%d",a); C. 1 D. 5 Right shift 4 times of 22 is 22/16 = 1 (integer division) 10 Find the output: void main() int a,b; a=3,1; b=(5,4); printf("%d",a+b); 11 Which of the following condition checks will print 10 twice? void main() int a=10; if( ) printf("\n%d",a); else printf("\n%d %d",a,a); 12 main ( ) int a=5; int b = a % ( a a /2 ) ( a 3 ) + a ; printf( %d,b); return 0 ; 14 int i=1; i += i*i>>2+3; A. 7 Answer: A B. 8 C. 6, can also be used as an D. Error operator and it has the least precedence. So in the first statement assignment is done first. In the second, assignment is done later. A. a==10 Answer : C B. a <= 10 Explanation : printf returns C. printf("\n number of characters printed. %d",a) So the first 10 can be printed D. None of the using the condition. Since the above statement prints more than 0 characters, the IF condition is true and hence the IF part will print one more 10. 9 Answer : B Answer : 5 % (5 5/2 ) ( 5 3)+5 = 5 % ( 5 2 ) (5 3 ) + 5 = 5 % 3 2 + 5 = 2 2 + 5 = 9 a. 1 a b. 2 The precedence order is *, +, c. 4 >> and lastly += d. 7 Therefore Ans = 1 + ((1 *1)>>(2+3)) = 1 + ((1)>>(5)) =

printf("%d",i); return 0; Give the result of compiling and running the above program? 15 int i=1; i += i*i<<2+3; printf("%d",i); return 0; Give the result of compiling and running the above program? a. 15 b. 24 c. 33 d. 34 1+0 = 1 c. The precedence order is *, +, >> and lastly += Therefore Ans = 1 + ((1 *1)<<(2+3)) = 1 + ((1)<<(5)) = 1+32 = 33 16 char a,b,c; a = 'b'; b = 'c'; c = 'A'; b=c;c=b; a=c;c=a; printf("a%cb%cc%c",a,b,c); What will be the output printed by the printf statement? a. AABbCc b. AABbCc c. AABACA d. AcBbCA c. b = c => b = 'A' c = b => c = 'A' a = c => a = 'A' c = a => c = 'A' Programming Question #1 Write a program to find the number of perfect squares between given two numbers A and B (both inclusive). A number is called a perfect square if it can be written as x*x for some integer x. Constraints: Both A and B are positive. They both are less than 100,000. Input: Two numbers A and B separated by a space Output: Count of the number of perfect squares

Example 1: Input: 3 10 Output: 2 Example 2: Input: 16 70 Output: 5 Public Test cases: 1. 3 10 2 2. 16 70 5 3. 11 99 6 Private Test cases: 1. 1 100 10 2. 17 124 7 3. 1 2 1 4. 46 47 0 5. 10000 20000 42 Solution: int x,y,i,a; int count=0,flag=0; scanf("%d %d",&x,&y); for(i=x;i<=y;i++) for(a = 0; a <= i; a++) if (i == a * a)

flag=1; if(flag==1) count++; flag=0; printf("%d",count); return 1; Programming Question #2 Write a program to find whether a given number (say x) is a perfect number or not. Definition of Perfect number: A perfect number is a positive integer that is equal to the sum of its proper positive divisors. Take number 6. Proper positive divisors of 6 is 1,2,3 and their sum is 1+2+3=6. So, 6 is a perfect number. Constraint: x>=1 Input: A single number x Output: yes if given number x is a perfect number no if given number x is not a perfect number Example 1:

Input: 6 Output: yes Example 2: Input: 7 Output: no Public Test cases: 1. 6 yes 2. 10 no 3. 28 yes Private Test cases: 1. 1 no 2. 496 yes 3. 8128 yes 4. 1000 no 5. 4042 no 6. 33550336 yes Solution: int x,i,sum=0; scanf("%d",&x); for(i=1;i<x;i++) if(x%i==0) sum+=i;

if(sum==x) printf("yes"); else printf("no"); return 1; Programming Qn #3 Write a C program that takes a positive number N and produces an output that is the product of its digits. Take number 657. Answer expected : 6 * 5 * 7 = 210 Constraint: 1<=N<=999999 Input: A single number Output: The value Example 1: Input: 657 Output: 210 Example 2: Input: 7 Output: 7 Public Test cases: 1. 657 210 2. 41 4 3. 931 27 Private Test cases: 1. 1 1 2. 201 0 3. 1234 24

4. 5555 625 5. 10156 0 6. 999999 531441 7. 124356 720 8. 111111 1 Programming Qn #4 Given three points (x1, y1), (x2, y2) and (x3, y3), write a program to check if all the three points fall on one straight line. INPUT: Six integers x1, y1, x2, y2, x3, y3 separated by whitespace. OUTPUT: Print Yes if all the points fall on straight line, No otherwise. CONSTRAINTS: -1000 <= x1, y1, x2, y2, x3, y3 <= 1000 Public Test cases: 1. 1 0 0 0 3 0 Yes 2. -2 0-2 1-2 2 Yes 3. -62 14-18 -23-6 23 No