CSE-122: Programming Problem Solving: Easy & Important Questions with Solution
Output Tracing:
1. What will be the output of the following code segments?
#include<stdio.h>
int main() {
int p = 3, q = 7, r = 9;
r = p*3;
printf("1. P = %d\n", p*=3);
q = ++p - r--;
printf("2. P = %d Q = %d\n",p++,--q);
r = (--q) + (p++);
printf("3. %d - %d\n", q--, ++r);
return 0;
}
|
|
Answer:
2. What
will be the output of the following code segments?
|
|
#include <stdio.h>
int
main(){
int i,n = 1;
for(i=1; i<20; i+=2, n++){
if(n % 5 == 0){
printf("H2O\n");
n*=2;
continue;
}
if(n%9 == 0){
printf("Water\n");
break;
}
else{
n+=2;
printf("Restaurant\n");
}
}
return 0;
}
|
|
Answer:
3. What
will be the output of the following code segments?
#include <stdio.h>
void Boom(int a, int *b)
{
*b = *b + a;
}
int Start()
{
int a = 5, b = 7, *p;
p = &a;
(*p)++;
Boom(*p, &b);
printf("%d
%d\n", a, b);
return *p;
}
int main()
{
int x = Start();
printf("Start :
%d\n", x);
}
Answer:
4. What
will be the output of the following code segments?
#include <stdio.h>
int main()
{
char sure[100] =
"What about the Nomination!", *ptr;
ptr = sure;
ptr++;
printf("%s\n", ptr);
sure[4] = '\0';
++ptr;
printf("%s\n", sure);
}
Answer:
Problem solving: Solve
the following problems.
5.
Have you ever heard of “Give Away!” problem?
Ok, this is the Give Away
problem of this Exam! You have to write a C program that will take input
two integer a & b and also print b & a.
Sample Input: 3
5
Sample Output: 5 3
|
Sample Input:
7 13
Sample Output:
13 7
|
Answer:
6. You
were riding on Uber from Nilkhet to CSE Building with an
initial speed of U (u) and last speed was V(v). Acceleration of the bike was A
(a). So now write a C program that will take three input: U V and A and will
output the required time T (t). You
should use the given formula to calculate T (t).
v = u + at
Sample
Input: 5 10 2
Sample
Output: 2.5
|
Sample
Input: 7 14 3
Sample
Output: 2.33
|
Answer:
7.
Its 8:00 AM. You have a PPS Exam on 10:00
AM to 12 AM inclusive. You have now hired a Pathao Ride. It will
take T hours to reach CSE building where your Exam will be held.
Now write a C program that will take input the required time T to
reach and print “Aya Porsi!” if you reach before 10 AM. Otherwise print “Shuru Hoya Gelo!” if
you reach during the exam and if you reach after the exam time, print “Khaise!”.
Sample Input: 3
Sample Output: Shuru Hoya Gelo!
|
Sample Input: 1
Sample
Output: Aya Porsi!
|
Answer:
8. Write
a C program that will take input two integers a & b and count
the number of integers that are divisible by 4.
Sample Input: 1 10
Sample Output:
2
|
Sample Input: 8 20
Sample Output: 4
|
Answer:
9. Write
a C program that will take input an array of 10 integer number and print
only the numbers that are between 3 and 7 in reverse of
their appearance!
Sample Input:
1 3 5 4 9 8 3 10 4 9
Sample Output:
4 3 4 5 3
|
Sample Input:
2 1 3 5 2 6 1 2 4 9
Sample Output: 4 5
3 6
|
Explanation: In the first Sample, Numbers between 3 and 7
has appeared [ 3 5 4 3 4] in this way, but you have to print in reverse, [4 3 4
5 3].
Answer:
10.
Do you heard
about Time Dialiation? Special
relativity states that time can pass at different rates in different reference
frames. Ovserve the following equatuion.
t1 =
t * sqrt(1 – v2 / c2)
Given
the value of t
1 & v
can you calculate the
Stationary time
Print to two decimal points. Value of C =
299792.458
(KM)
Sample
Input: 20 20000
Sample
Output: 20.04
|
Sample
Input: 27 30001
Sample
Output: 27.14
|
Answer:
11.
You are given
3 integers. First one is the available balance (in BDT) in your mobile phone.
The second, the call rate (in BDT / minute). Finally, the amount of time you
want to talk (in minutes). Write a program that will print “Call” if you
have sufficient balance left or “Recharge” otherwise.
Sample Input: 20 2 5
Sample Output: Call
|
Sample
Input: 2 2 5
Sample
Output: Recharge
|
Answer:
12. What will be the output of the following code segments?
Answer:
13. What will be the output of the following code segments?
Answer:
14. Write code segments according to the instructions:
Answer:
15. Write a C function to check if a number is prime or not.
Answer:
15. Write a C function Calculate() that will have an integer parameter and calculate the square and the cube of that integer and return the values.
Hint: Use call by reference.
Answer:
16. Solve the following problem:
Answer:
17. Solve the following problem:
Answer:
18. Solve the following problem:
Answer:
19. Solve the following problem:
Answer:
20. Solve the following problem:
Answer:
No comments