pps notes
pps notes
y=x++;
printi("%d);
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");
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");
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
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.
Example 2:
Input: 16 70
Output: 5
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:
Example 1:
Input 6
Output yes
Eample:
Input 7
Output: no
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
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