Programming For Problem Solving (Csen 1001)
Programming For Problem Solving (Csen 1001)
Group – A
(Multiple Choice Type Questions)
Group – B
2. (a) “Storing negative numbers using 1’s complement or 2’s complement
representation rather than signed magnitude representation leads to
substantial saving in circuitry” – Is the above statement TRUE or FALSE? Give
reasons against your answer.
(b) Find the sum of the following binary numbers represented in a 5-bit sign-
magnitude register and that uses 1’s complement to represent negative
numbers:
(i) -0110 and -0111
(ii) + 0011 and - 1101
(c) Draw a flowchart to print the sum of the digits of a number given by the user.
(1 + 2) + (2 + 2) + 5 = 12
Group – C
4. (a) Consider the following code snippets written in C along with their outputs. Give
the reasons in detail behind the results for each of the following cases.
i)
int main ()
CSEN 1001 2
B.TECH/AEIE/CSBS/CSE/ECE/IT/2ND SEM/CSEN 1001/2021
{
int a = 1, b = 2, c = 3;
printf (“%d \n", a += (a += 3, 5, a));
return 0;
}
The above code returns the output 8.
ii)
int main ()
{
int m=1, n=1, r=1, s=3, t=5, x;
x=++m && n++ && --r && s/2 && ++t;
printf ("\n m=%d, n=%d, r=%d, s=%d, t=%d, x=%d", m, n, r, s, t, x);
return 0;
}
The output of the above code is:
m=2, n=2, r=0, s=3, t=5, x=0
iii)
int main ()
{
int i =1024;
for (; i; i>>=1)
printf (“Hello world\n”);
return 0;
}
The above program prints “Hello World” 11 times.
(b) Write a C program to find which of the numbers is odd and which of the
numbers is even from a set of numbers given by the user using bitwise AND
operator.
Note that you don’t know in advance how many numbers are there and that’s
why you are not allowed to use array.
(3 + 2 + 2) + 5 = 12
5. (a) Consider the weekly salary of a salesperson who is selling some domestic
products. If x is the number of products sold in a week, then the weekly salary is
given by the following rules:
4x + 100 for x < 40
Salary = 300 for x = 40
4.5x + 150 for x > 40
(i) Write the if…else statements in C language to represent the above rules
Replace the if…else statements written in part (i) above with its equivalent
expression using conditional operator.
(b) Suppose you want to write a ‘if’ statement in a C program as follows, where
‘payCode’ is an integer variable:
if (payCode = = 4)
CSEN 1001 3
B.TECH/AEIE/CSBS/CSE/ECE/IT/2ND SEM/CSEN 1001/2021
printf (“\n You get a bonus”);
But by mistake the ‘if’ statement is written as follows:
if (payCode = 4)
printf (“\n You get a bonus”);
Do you get the same result for this mistake? Give reasons against your answer.
(c) Write a C program to print the following pattern where the number of rows in
the pattern is a user input.
****
***
**
*
**
***
****
(2 + 2) + (1 + 2) + 5 = 12
Group – D
6. (a) What do you mean by storage class of a variable in C language? What is the
default storage class of C variables? What is the scope and longevity of static
variables?
(b) How can you allocate a 2-D integer array with 2 rows and 3 columns
dynamically in C? Show the steps using an example
(c) Write a C program to insert an element (given by the user) into an array at a
particular valid position (given by the user) assuming that the array is not full.
Insertion will take place in an user defined function, which will be called by your
main() by passing the array and the position where insertion will take place.
You should access the array elements by using pointers only.
(2 + 1 + 1) + 3 + 5 = 12
7. (a) Write a recursive function in C language that will print the binary equivalent of a
given positive integer. Note that your program should not contain any
iterations, like ‘for loop’, ‘while loop’, ‘do-while loop’.
(b) What is the effect of accessing a [5] in an integer array of size 5 i.e., int a [5]?
(c) The header file string.h contains a library function strcat (string1, string2), that
appends character array string2 to the character array string1. Write a C
program using function that will behave exactly the same way strcat (string1,
string2) behaves. Elements of character arrays will be accessed through
pointers.
5 + 2 + 5 = 12
CSEN 1001 4
B.TECH/AEIE/CSBS/CSE/ECE/IT/2ND SEM/CSEN 1001/2021
Group – E
8. (a) Write a C program which will print the executable file name when you run your
program. You are also supposed to show how you run the program from the
command prompt.
(b) How can you test whether a file is opened successfully or not? Give example.
(c) Write a C program to copy the contents of a source file to a destination file,
where names of both files are supplied as command line arguments.
3 + 3 + 6 = 12
Department &
Submission Link
Section
AEIE https://classroom.google.com/c/MzEyOTI5NTQ1MzU2/a/Mzc0MjE2MTk4NTg0/details
CSBS https://classroom.google.com/c/MzExOTEwMDk0ODcw/a/Mzc0MTk4MDQ0NjY0/details
CSE - A https://classroom.google.com/c/MzExMDM2MDMwMjg5/a/Mzc0MjIxMTM1MDU4/details
CSE - B https://classroom.google.com/c/MzEyMTgwMTgyNzM5/a/Mzc0MjI0MjA2MDUw/details
CSE - C https://classroom.google.com/c/MjgwODI4MDc4NDE2/a/Mzc0MTM2ODk1NjQ3/details
ECE - A https://classroom.google.com/w/Mjk3MjI5Nzc2MDk4/t/all
ECE - B https://classroom.google.com/c/MzEyNTE0NzAyMTc1/a/MzcxNjYwNTUwMjY1/details
ECE - C https://classroom.google.com/w/Mjk3MjQwNTM1Mzcz/t/all
IT https://classroom.google.com/c/MzExNjAwMzk2OTA5/a/Mzc0MjA4MTEyNTM0/details
CSEN 1001 5