0% found this document useful (0 votes)
14 views10 pages

pps notes

The document contains a series of programming questions and their respective answers, focusing on C programming concepts such as output evaluation, perfect squares, perfect numbers, and checking collinearity of points. Each question includes code snippets, expected outputs, and explanations. Additionally, it provides public and private test cases for validation.

Uploaded by

mexaneddo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views10 pages

pps notes

The document contains a series of programming questions and their respective answers, focusing on C programming concepts such as output evaluation, perfect squares, perfect numbers, and checking collinearity of points. Each question includes code snippets, expected outputs, and explanations. Additionally, it provides public and private test cases for validation.

Uploaded by

mexaneddo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Week 1 Questions

St. Question Options Answer &Explanation

1 Find the output: A. 10 Answer: D


#include<stdio.h> B 20
int main) C. 21 Explanation:
D. 11 X++ increments the value to 11.
{ Soprintf statement uses x=11.
int x=10; int y

y=x++;

printi("%d);

2 Find the output: A. 97 Answer: A


#include<stdio.h> B 98
int main) C. 99 Explanation:
D. 'a' The ASCIlvalue of 'a' is 97
char c='a; which gets switched while
switch(cX switching the char c
case 97:
printi("97"):
break;
case 98:
printf("98"):
break;
case 99:
printf("99"),;
break;
default:
printf("default");
Find the output: A 1,10 Answer: C
includecstdio.h> 3 9,11
irt main0 C. 9,19 Explanation: The expression
D. 1,19 b*c+d-a gets evaluated first,
{
int x=10; which then sets the value of a
int a=l,b=2,c=3,d=4; to 9. This value is used for
=bc+d-a incrementing x.
print(%d,9%d",ax);

A. YES Answer:B
Fnd the output:
tncludecstdio.h> B. NO
int main0 C. Error Explanation:
{ int b = 1.1assigns 1 to b.
float a=1.1; Comparing a=-b compares 1
int b=1.1; with 1.1 which is FALSE.
(a=-)
printf("YES);
else
printf("NO");

5 Find the Output: 11 Answer: B


incudecstdio.h>
int main) Explanation:
The semicolon after the for loop
int i,x=10; terminates it and the brackets
lor(j=0;i<2,1+); are treated as a single block,
thus x++ is executed only once.

print("%d"x);,
6 Find the output: 13 Answer: A
include<stdio.h>
int main) Explanation:
Condition is evaluated to true
int i=-10; for any non-zero value, So, the
first and last IF conditions are
printf("1"); evaluated as TRUE.

*=0;

printf(2"):
iF5;

printf("3");

7 Find the output: A 10 Answer: C


#include<stdio.h> B 11
int main) C. 12 Explanation:
D. 13 The do loop executes once and
int x=10; E. The goes to the check. In the check,
do{ program runs for there is one more increment.
X++; more than 10 So the final answer is 12.
}while(x++>12); iterations.
print(%d"x);

9 Find the output: A. 2 Answer: C


void main0{ B. 3
Explanation:
22, C. 1 Right shift 4 times of 22 is
D. S 22/16 = 1 (iteger division)
prtnti(d,

20 Find the output: A. 7 Answer:A


volid main0l B. 8 Explanation:
int a.b; C. 8 ,can aso be used as an
=3.1; D. Error operator and i has the least
b-5,4): precedence. So in the first
statement assignment is done
printi( %da+b): first. In the second, assignment
is done later.
11 Which of the following condition A. a==10 Answer:C
checks will print 10 twice? B. a< 10 Explanation :printf returns
C. printf(n number of characters printed.
void main0 %d"a) So the first 10 can be printed
int a=10; D. None of the using the condition. Since the
above statement prints more than 0
printf(n9%d", a); characters,the IF condition is
else true and hence the IF part will
prindi(n%d 6d",a,a); print one more 10.

12 #include<stdio.h> Answer :B
main () Answer:
5 % (5 - 5/2 ) * (5 -3)+5
int a-5; =5 %(5-2)*(5-3)+
5
int b=a % (a-a /2 ) * (a
-3)+ a; =5%3 * 2 +5

print("%d"b); =2 *2 +5
=9
return 0;

14 #include<stdio.h> a. 1 a

b. 2 The precedence order is *, +,


int main0{ c. 4 >> and lastly +=
int i=1; d. 7 Therefore Ans =1+ (1
Í+= ii>>2+3; *1>>(2+3) =1+(1>>5)) =
rint(d ). 1+0 = 1
return 0,

Give fhe resul of compiling and


running the above program?
15 tincludecsidio.h a. 15
b. 24
int main( c. 33 The precedence order is , +,
int i=1. d. 34 >>and lastly +=
i4z tic<2+3; Therefore Ans =1+ (1
print("%d): *1)<<(2+3) =1+(1)<<(5) =
return 0; 1+32 =33

Give the result of compiling and


running the above program?
16 char a,b,c; a. AABbCc
a=b: b. AABbCc b=c=> b='A'
b='c; c. AABACA c=b=>c='A'
c='A; d. AcBbCA a=c=>a='A'
b=c;c=b; C=a => C='A'
a=c;c=a;
printf("'A9%cB%cC%c a,b,c);
What willbe the output printed
by the printf statement?

Programming Question #1

Write a program to find the number of perfect squares between given two numbersAand B
(both inclusive). Anumber is called a perfect square if it can be writen as x*x for some integer x.
Constraints:
Both A
and Bare positive. They both are less than 100,000.

Input: Two numbers Aand Bseparated 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:

Number Input Output


1. 3 10 2
2. 16 70
3. 11 99

Private Test cases:

Number Input Output


1, 1100 10
2. 17 124 7
3. 12 1
4. 46 47 0
5. 10000 20000 42

Solution:

#include<stdio.h>

int main0{
int x,yi,a;
int count=0,flag=0;

scanf("%d %d",&x,&y);

for(=x;i<=y;it+X
for(a = 0; a <= i; a++)

if ( == a*a)
lng1.

H(tlmge 1)
count4;
fing-0,

prinf("hd' count).
return 1.:

Programming Question #2

write a program to find whether a given number (say x) is a "perfect number or not.
Detinition of Perfect number:
Apertec number is a positive integer that is equal to the sum of its proper positive divisors.

Explanation:
Take number 6.
Proper positive divisors of 6 is 1,2,3 and their sum is 1+2+3=6.
So, 6 is a pertect number.

Constraint:

input: Asingle number x


Output:
yes itgiven number x is a perfect number
no ifgiven number x is not a perfect number

Example 1:
Input 6
Output yes

Eample:
Input 7
Output: no

Public est casess:

Number Input Output


1 6 yes
2 10 no
3 28 yes

Priate Test caSes:

Number Input Output


1 1 no
2 496 yes
8128 yes
1000 no
5 4042 no
6 33550336 yes

Solution:

#include<stdio.h>

int main0{
int x,i,sum=0;

scanf("%d",&);
for(i=1,i<xi++X
if(xhi==0)
sum+=i;
(sum=)
printf("yes");:
Jelse(
print("'no"):
return 1:

Programming Qn #3
Write a Cprogram that takes a positive number N and produces an output that is the product of
its digits.

Explanation:
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:


Number Input Output
1, 657 210
41 4
2.
3. 931 27
Private Test cases:
Number Input Output
1. 1

2 201
3 1234 24
5555 625
5 10156
6 999999 531441
7 124356 720
111111

Programming Qn #4

Given three points (X1, y1), (x2, y2) and (x3, y3), write a program to check if all the
three points fallon 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:
Number Input Output
1. 100030 Yes

2. -20-21-22 Yes
3. 62 14 -18 -23 -6 23 No

You might also like