0% found this document useful (0 votes)
31 views47 pages

C Practice Questions

Uploaded by

sangameshmagibec
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)
31 views47 pages

C Practice Questions

Uploaded by

sangameshmagibec
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

C Practice - Test 1 - Oct 9, 2017

Roll No Name

• Duration: 2.00 to 4.30 pm


• Submit your code at [email protected]. For partial code, explain the logic and include
them as comment
• You are free to use Internet, reuse code developed as part of assignment.
• Avoid copying as plagiarism check will be done for all submitted codes. Hence, no evaluation will be
done during the examination hours.
1. (10 marks) Consider a two-wheeler servicing agency. For every request serviced by the agency, the
following charges are levied along with taxes.
(i) Water wash - Rs. 200 + 6% tax
(ii) Oil in the Engine must be at least 100 ml. If it goes below 100 ml (ask the user to input the current
level of oil in the engine), top up is done by the agency (the value of top up is given by the user so
that level is at least 100 ml). Cost of 1 ml is Rs. 3 + 12.5% tax
(iii) cost for general service is Rs. 600+14.5% tax. Write a C program to accomplish the following tasks.

(a) Define suitable variables to capture the above three parameters and respective taxes
(b) Calculate the total amount to be paid.
(c) Display the total with 17 places which includes 7 places for fraction. The integer part of the total
must be prefixed with 0’s and a sign, if required.
(d) Display the floor value of total (the largest integer that is smaller than the value of total) and ceil
value of total (the least integer that is greater than the value of total). Example: floor of 14.765 is 14
and ceil of 14.765 is 15

Space for Evaluation


• (2 marks) Variable declaration
• (2 marks) computation of total
• (1+1 marks) formatted output as per (c)
• (4 marks) floor and ceil
2. (10 marks) Visit www.iiitdm.ac.in and identify the courses that you will be doing in 5th semester.
Accept from the user, the marks of all subjects in 5th semester for 3 students. Grade them using the
following scheme.
• if marks scored is avg+5 or avg-5 then grade B
• if marks scored is more than avg+5 and less than or equal to avg +10 then grade A
• if marks scored is more than avg+10 then grade S
• if marks scored is less than avg-5 then grade I
Space for Evaluation
• (3 marks) Variable declaration/input acceptance
• (3 marks) computing average
• (4 marks) displaying grade sheet for 3 students
3. (10 marks) How many numbers are there in the range [1..100] that are neither divisible by 3 nor 4 nor
5. Write a C program to print the number. Can we solve this problem using just sequence statements.
If so, make an attempt. Think of a good logic before attempting this question.

(i) (5 marks) Logic (ii) (5 marks) Displaying the count

1
C Practice - Test 1 - Oct 9, 2017
Roll No Name

• Duration: 2.00 to 4.30 pm


• Submit your code at [email protected]. For partial code, explain the logic and include
them as comment
• You are free to use Internet, reuse code developed as part of assignment.
• Avoid copying as plagiarism check will be done for all submitted codes. Hence, no evaluation will be
done during the examination hours.
1. (10 marks) Consider a mobile servicing agency. For every request serviced by the agency, the following
charges are levied along with taxes.
(i) Mobile Recharge - Rs. 100 + 12% tax
(ii) Mobile top up - Rs. x + 18% tax
(iii) cost for general service is Rs. 200+14.5% tax. Write a C program to accomplish the following tasks.

(a) Define suitable variables to capture the above three parameters and respective taxes
(b) Ask the user the type of service (recharge, top up, general). If it is top up, ask the value of x.
(c) Calculate the total amount to be paid.
(d) Display the total with 14 places which includes 6 places for fraction. The integer part of the total
must be prefixed with 0’s and a sign, if required.
(d) Display the floor value of total (the largest integer that is smaller than the value of total) and ceil
value of total (the least integer that is greater than the value of total). Example: floor of 14.765 is 14
and ceil of 14.765 is 15

Space for Evaluation


• (2 marks) Variable declaration/input
• (1 mark) computation of total cost
• (1+1+1 marks) formatted output as per (c) and (d)
• (4 marks) floor and ceil
2. (10 marks) Visit www.iiitdm.ac.in and identify the courses that you will be doing in 7th semester.
Accept from the user, the marks of all subjects in 7th semester for 3 students. Grade them using the
following scheme.
• if marks scored is avg+5 or avg-5 then grade B
• if marks scored is more than avg+5 and less than or equal to avg +10 then grade A
• if marks scored is more than avg+10 then grade S
• if marks scored is less than avg-5 then grade I
Space for Evaluation
• (3 marks) Variable declaration/input acceptance
• (3 marks) computing average
• (4 marks) displaying grade sheet for 3 students
3. (10 marks) How many numbers are there in the range [1..100] that are neither divisible by 2 nor 3 nor
5. Write a C program to print the number. Can we solve this problem using just sequence statements.
If so, make an attempt. Think of a good logic before attempting this question.

(i) (5 marks) Logic (ii) (5 marks) Displaying the count

1
C Practice - Test 1 - Oct 11, 2017
Roll No Name

• Duration: 2.00 to 4.30 pm


• Submit your code at [email protected]. For partial code, explain the logic and include
them as comment
• You are free to use Internet, reuse code developed as part of assignment.
• Avoid copying as plagiarism check will be done for all submitted codes. Hence, no evaluation will be
done during the examination hours.
1. (10 marks) Consider a photo copy/xerox servicing agency. For every request serviced by the agency,
the following charges are levied along with taxes.
(i) Photo copy - Rs. 2 + 12% tax
(ii) Spiral binding - Rs. 50 + 18% tax
(iii) Print out - Rs. 3 + 6% tax
Write a C program to accomplish the following tasks.
(a) Define suitable variables to capture the above three parameters and respective taxes
(b) Ask the user the type of service (photo, spiral, print). Also, ask the value of x which denotes the
number of photo copies/spiral/prints.
(c) Calculate the total amount to be paid.
(d) Display the total with 11 places which includes 4 places for fraction. The integer part of the total
must be prefixed with 0’s and a sign, if required.
(e) Display the floor value of total (the largest integer that is smaller than the value of total) and ceil
value of total (the least integer that is greater than the value of total). Example: floor of 14.765 is 14
and ceil of 14.765 is 15
Space for Evaluation
• (2 marks) Variable declaration/input
• (1 mark) computation of total cost
• (1+1+1 marks) formatted output as per (c) and (d)
• (4 marks) floor and ceil
2. (10 marks) Visit www.iiitdm.ac.in and identify the courses that you will be doing in 3rd semester.
Accept from the user, the marks of all subjects in 3rd semester for 3 students. Grade them using the
following scheme.
• if marks scored is avg+5 or avg-5 then grade B
• if marks scored is more than avg+5 and less than or equal to avg +10 then grade A
• if marks scored is more than avg+10 then grade S
• if marks scored is less than avg-5 then grade I
Space for Evaluation
• (3 marks) Variable declaration/input acceptance
• (3 marks) computing average
• (4 marks) displaying grade sheet for 3 students
3. (10 marks) Accept four numbers from the user. Write a C program (with a good logic) that prints (i)
increasing sequence among four (ii) decreasing sequence among four. For example: if the input is -2,
4, 1, -5, then increasing sequence is -5,-2,1,2 and decreasing sequence is 2,1,-2,-5.

(i) (5 marks) Logic (ii) (5 marks) C program

1
C Practice - Test 1 - Oct 11, 2017
Roll No Name
• Duration: 2.00 to 4.30 pm. Submit your code at [email protected]. For partial code,
explain the logic and include them as comment
• You are free to use Internet, reuse code developed as part of assignment.
• Avoid copying as plagiarism check will be done for all submitted codes. Hence, no evaluation will be
done during the examination hours.
1. (10 marks) Consider a courier (parcel) agency. For every request serviced by the agency, the following
charges are levied along with taxes.
(i) Simple Courier - Rs. 20 + 12% tax
(ii) Parcel below 1 kg - Rs. 100 + 18% tax
(iii) Parcel greater than or equal to 1 kg - Rs. 200 + 18% tax
(iii) Parcel medicines - Rs. 300 + 6% tax
Write a C program to accomplish the following tasks.
(a) Define suitable variables to capture the above three parameters and respective taxes
(b) Ask the user the type of service (courier, parcel below, parcel above, medicine). Also, ask the value
of x which denotes the number of courier/parcel/.
(c) Calculate the total amount to be paid.
(d) Display the total with 13 places which includes 5 places for fraction. The integer part of the total
must be prefixed with 0’s and a sign, if required.
(e) Display the floor value of total (the largest integer that is smaller than the value of total) and ceil
value of total (the least integer that is greater than the value of total). Example: floor of 14.765 is 14
and ceil of 14.765 is 15
Space for Evaluation
• (2 marks) Variable declaration/input
• (1 mark) computation of total cost
• (1+1+1 marks) formatted output as per (c) and (d)
• (4 marks) floor and ceil
2. (10 marks) Visit www.iiitdm.ac.in and identify the courses that you will be doing in 4th semester.
Accept from the user, the marks of all subjects in 4th semester for 3 students. Grade them using the
following scheme.
• if marks scored is avg+5 or avg-5 then grade B
• if marks scored is more than avg+5 and less than or equal to avg +10 then grade A
• if marks scored is more than avg+10 then grade S
• if marks scored is less than avg-5 then grade I
Space for Evaluation
• (3 marks) Variable declaration/input acceptance
• (3 marks) computing average
• (4 marks) displaying grade sheet for 3 students
3. (10 marks) Answer this question without using For loop and mod operator. You are permitted to
use IF, GOTO. Question: Accept a 7 digit number from the user. Write a C program that checks (i)
whether the number is divisible by 3 (ii) whether the number is divisible by four. For example: if the
input is 1234533, then divisible by 3. if it is 1234536, then divisible by 4. You must discover two logic
to solve this problem, of which, write C code for one logic and write the other logic in this sheet.
(i) (6 marks) Logic (ii) (4 marks) C program

1
C Practice - Test 2 - Nov 08, 2017

Roll No Name

• Submit your code at [email protected]. For partial code, explain the logic and include
them as comment.
• You are free to use Internet, reuse code developed as part of assignment. Avoid copying as plagiarism
check will be done for all submitted codes.

1. Write a C program that prints the boundary of a thatched roof house (as illustrated in the figure).

Space for evaluation:


(3 marks) for drawing base of the house
(3 marks) for drawing the roof
(4 marks) for proper alignment

2. Accept a sequence of characters including numbers, special characters, tab, white space and newline.
Print all accepted characters in reverse order.
Space for evaluation:
(3 marks) input acceptance as prescribed
(3 marks) for handling special characters, tab, white space and newline properly
(4 marks) printing in reverse order

3. Consider an array of size 10 which is filled with values from the range [0..10]. Write a C-program that
prints the multiplicities (the number of times it appears in the array) of each number. Is it possible to
get multiplicities without using looping statements. If so, write the logic (no need to write c-code for
this logic). If not possible, justify the impossibility.
Space for evaluation:
(2 marks) input acceptance as prescribed
(4 marks) computing multiplicities and printing
(4 marks) Alternative logic.

1
C Practice - Test 2 - Nov 08, 2017

Roll No Name

• Submit your code at [email protected]. For partial code, explain the logic and include
them as comment.
• You are free to use Internet, reuse code developed as part of assignment. Avoid copying as plagiarism
check will be done for all submitted codes.

1. Write a C program that prints the boundary of a stair case with four steps as illustrated in the figure.
Space for evaluation:
(3 marks) for drawing steps
(3 marks) for drawing the line connecting steps
(4 marks) for proper alignment

2. Accept a sequence of numbers, including special characters, tab, white space and newline. Print the
ASCII value of all accepted characters in reverse order.
Space for evaluation:
(3 marks) input acceptance as prescribed
(3 marks) for handling special characters, tab, white space and newline properly
(4 marks) printing ASCII in reverse order

3. Consider an array of size 10 which is filled with distinct values from the range [0..10] (no value is used
more than once). Since array size is 10 and there are 11 values (0 to 10), one value from the range
is missing in the array. Write a C program to identify the missing value from [0..10]. Also, write a
program to identify the missing value using just sequence statements. Note that the logic you come up
with must be scalable, i.e., it must work for any array size. Suppose, we modify the question slightly
and allow exactly one value from the range [0..10] to appear twice and all other values appear at most
once. This means, two values from the range [0..10] are missing. Write a C program to identify the
two missing ones.
Space for evaluation:
(2 marks) input acceptance as prescribed
(2 marks) Identifying missing one and printing
(3 marks) missing one using sequence statement
(3 marks) two missing ones

1
C Practice - Test 2 - Nov 06, 2017

Roll No Name

• Submit your code at [email protected]. For partial code, explain the logic and include
them as comment.
• You are free to use Internet, reuse code developed as part of assignment. Avoid copying as plagiarism
check will be done for all submitted codes.

1. Write a C program that prints the boundary of a cube as illustrated in the figure.
Space for evaluation:
(6 marks) for drawing 12 lines
(4 marks) for proper alignment

2. Accept from the user today’s date and your Date of birth in the format dd-mm-yyyy. Calculate, the
number of minutes you existed on earth as of this date. Also, calculate the number of leap years you
have witnessed till date and print all of them.
Space for evaluation:
(2 marks) input acceptance as per the format
(3 marks) computation and printing
(3 marks) leap year computation and printing

3. Accept from the user an integer r. Consider the equation x + y + z = r. How many non-negative
integer solutions are there satisfying this equation. List all of them. For example, if r = 2, the
possible solutions are (2, 0, 0), (1, 1, 0), (0, 1, 1), ... and so on. Further, (i) compute all solutions with
the additional constraint x ≥ 0, y ≥ 2, z ≥ 1. (ii) Is it possible to get the number of solutions (just the
count) using sequence statements.
Space for evaluation:
(1 mark) input
(3 marks) listing solutions and count when no constraints
(4 marks) listing solutions and count when constraints
(4 marks) count using sequence statements

1
C Practice - Test 2 - Nov 06, 2017

Roll No Name

• Submit your code at [email protected]. For partial code, explain the logic and include
them as comment.
• You are free to use Internet, reuse code developed as part of assignment. Avoid copying as plagiarism
check will be done for all submitted codes.

1. Write a C program that prints the boundary of a cylinder as illustrated in the figure.
Space for evaluation:
(3 marks) for drawing circle/ellipse
(3 marks) for drawing lines
(4 marks) for proper alignment

2. Accept from the user today’s date and your Date of birth in the format dd-mm-yyyy. Assuming you
sleep 6 hours a day, read 10 hours and spend 1.5 hours a day for eating. How many minutes have you
spent as of this date for (i) sleeping (ii) eating. The number of years you have spent for reading as of
this date (amount of time spent for reading in years).
Space for evaluation:
(2 marks) input acceptance as per the format
(4 marks) computation and printing (i) and (ii)
(2 marks) reading years computation and printing

3. How many pairs (a, b) are there in the range [1..30] which are relatively prime (co prime). I.e., GCD(a,b)
is 1. Your program must be scalable, i.e., it must work if the range is [1..r] instead of [1..30]. List
all pairs in the range [1..30]. Is there a pair in the above listing whose linear combination gives every
integer starting from 10 until 30. For example, (2, 3) are relatively prime, and the integer 11 = 4·2+1·3,
12 = 6 · 2 + 0 · 3. In general, x = m · a + n · b and m, n are non-negative integers.
Space for evaluation:
(1 mark) input
(2+3+2 marks) GCD, Co prime checking and listing, count
(4 marks) linear combination

1
C Programming Practice - Test 2

Instructions:
1. All questions given here can be answered based on the concepts discussed in class. Therefore, Do NOT
use built-in functions and other features of C programming.
2. Duration: 14.00 to 17.00. You should mail your programs to [email protected] before
17.15. NO evaluation during the test hours.
3. Plagiarism check will be done for all programs and hence refrain yourself from copying.
4. You are free to use any online resources.
1. A teacher conducts a monthly test for a group of 4 students. There are 3 subjects with maximum
marks being 10 for each. Write a C program to answer the following. Your program must work for all
valid inputs and throw an error if invalid input is given.

(a) (1+2.5=3.5 marks) Variable declaration and Input acceptance: Ask the user to input marks of 3
subjects for 4 students. Must throw an error for invalid inputs. Marks with fractions are allowed
with at most one digit after the dot. Marks such as 3, 3.5 (exactly one digit after the dot is
allowed) are valid, whereas 3.45, 3.21 are invalid. Note that 3.20 is valid as it will be treated as
3.2.

(b) (1 mark) Computer Average for each subject for 4 students.

(c) (1.5 marks) Grade the students on all 3 subjects as per the following scheme. Grade S if marks
is at least twice the average. Grade A if marks is at least average+3 and below the cut off of ’S’.
Grade B if marks is exactly the average. Otherwise Grade C.

(d) (1+1.5+1.5=4 marks) Compute total marks for each student. Also, print the floor and ceil value
of the total without using floor/ceil functions.

2. Accept from the user 10 integers and a special integer x. Question: Check whether there exist a pair
of integers y and z in the input whose sum is x, i.e., x = y + z. Additionally, print all such pairs.
Logic: (3 marks) Write the logic below and trace your logic for the input; {1, 2, 3, 4, 5, 6, 1, −1, 0, −59},
x = 1. Further, write C program that implements this logic. (7 marks= variable declaration (1 mark),
logic (4 marks), printing all pairs (2 marks)).

1
C Programming Practice - Test 2

Instructions:
1. All questions given here can be answered based on the concepts discussed in class. Therefore, Do NOT
use built-in functions and other features of C programming.
2. Duration: 14.00 to 17.00. You should mail your programs to [email protected] before
17.15. NO evaluation during the test hours.
3. Plagiarism check will be done for all programs and hence refrain yourself from copying.
4. You are free to use any online resources.
1. Three students are participating in a carnatic music competition and they are evaluated on an integer
scale of 5 (0 to 5). There are three rounds of evaluation. Write a C program to answer the following.
Your program must work for all valid inputs and throw an error if invalid input is given.

(a) (1+1.5=2.5 marks) Variable declaration and Input acceptance: Accept the scores of each student
for each round. Throw an error if invalid input.

(b) (3 marks) For each round, students are graded as per the following scheme. Score= 4 or 5, then
Grade S, Score= 2 or 3, then Grade A, otherwise grade B. Grading must be implemented using
Switch-case and not by if-else.

(c) (3 marks) A student gets a title ’carnatic singer’ if he/she has secured at least one ’S’ or at least
two ’A’ in three rounds. Display all carnatic singers among three students.

(d) (1.5 marks) Compute average marks for each student over three rounds.

2. Accept from the user 10 integers. Question: For each element, print the multiplicities, the number of
times the element appears in the input.
Logic: (3 marks) Write the logic below and trace your logic for the input; {1, 2, 3, 4, 5, 6, 1, −1, 0, −59}.
Further, write C program that implements this logic. (7 marks= variable declaration and input accep-
tance (2 marks), logic (5 marks)).

1
C Programming Practice - Test 3
Mail your programs to [email protected] before 17.15.
1. Write a C program to perform the following;
(a) (2 marks) Accept a sequence of characters and special characters from the user. Special characters
can be any character that you find in Keyboard letters 1 to 0 (shift 1 gives !, shift 2 gives @...).
(b) (2 marks) Count the number of special characters in the input and display the count.
(c) (2 marks) For each character read, print the character along with its ascii value.
(d) (4 marks) Using a recursive function print all the characters read in reverse order.
2. (4:logic + 6:code) Write a C program to perform the following; Input: integer x, Output: Print x2
prime numbers. Your program must contain (i) at least one function apart from main() (ii) function
must have a return statement returning an integer/array.

C Programming Practice - Test 3


Mail your programs to [email protected] before 17.15.
1. Write a C program to perform the following;
(a) (2 marks) Accept a sequence of characters and special characters from the user. Special characters
can be any character that you find in Keyboard letters 1 to 0 (shift 1 gives !, shift 2 gives @...).
(b) (2 marks) Count the number of special characters in the input and display the count.
(c) (2 marks) For each character read, print the character along with its ascii value.
(d) (4 marks) Using a recursive function print all the characters read in reverse order.
2. (4:logic + 6:code) Write a C program to perform the following; Input: integer x, Output: Print x2
prime numbers. Your program must contain (i) at least one function apart from main() (ii) function
must have a return statement returning an integer/array.

C Programming Practice - Test 3


Mail your programs to [email protected] before 17.15.
1. Write a C program to perform the following;
(a) (2 marks) Accept a sequence of characters and special characters from the user. Special characters
can be any character that you find in Keyboard letters 1 to 0 (shift 1 gives !, shift 2 gives @...).
(b) (2 marks) Count the number of special characters in the input and display the count.
(c) (2 marks) For each character read, print the character along with its ascii value.
(d) (4 marks) Using a recursive function print all the characters read in reverse order.
2. (4:logic + 6:code) Write a C program to perform the following; Input: integer x, Output: Print x2
prime numbers. Your program must contain (i) at least one function apart from main() (ii) function
must have a return statement returning an integer/array.

1
Quiz 2- Device Drivers - Total marks 20 (one mark for each question)
Duration 1 hr.
1. What is ’struct file_operations’. Give an example.
2. What are the 4 components in ioctl command ID?
3. Explain ’dev_t’ type and its format.
4. Where is ’printk’ used? What is the use of ’loglevels’?
5. Explain blocking and non blocking operation.
6. What are the different classes of devices? Explain.
7. Write a ’Hello World’ module.
8. What are up, down functions? Give examples.
9. What are the differences between Kernel modules and Applications?
10. What is LINUX_VERSION_CODE and KERNEL_VERSION?
11. Explain ’mutex’ with an example.
12. What is module_param? What is its use?
13. What are the methods for device number allocation?
14. Explain 2 characteristics of policy free drivers.
15. Explain ’oops messages’. Give an example code which generates oops message.
16. Explain User space, Kernel space.
17. Draw a diagram to explain ioctl control flow from user application to HW. How major/minor numbers
help in identifying the driver and HW.
18. What is EXPORT_SYMBOL? Where is it used?
19. What is spin lock? what are the 2 values of spin lock?
20. Explain atomic bit operation. Give 2 functions used in atomic bit operations.

Quiz 2- Device Drivers - Total marks 20 (one mark for each question)
Duration 1 hr.
1. What is ’struct file_operations’. Give an example.
2. What are the 4 components in ioctl command ID?
3. Explain ’dev_t’ type and its format.
4. Where is ’printk’ used? What is the use of ’loglevels’?
5. Explain blocking and non blocking operation.
6. What are the different classes of devices? Explain.
7. Write a ’Hello World’ module.
8. What are up, down functions? Give examples.
9. What are the differences between Kernel modules and Applications?
10. What is LINUX_VERSION_CODE and KERNEL_VERSION?
11. Explain ’mutex’ with an example.
12. What is module_param? What is its use?
13. What are the methods for device number allocation?
14. Explain 2 characteristics of policy free drivers.
15. Explain ’oops messages’. Give an example code which generates oops message.
16. Explain User space, Kernel space.
17. Draw a diagram to explain ioctl control flow from user application to HW. How major/minor numbers
help in identifying the driver and HW.
18. What is EXPORT_SYMBOL? Where is it used?
19. What is spin lock? what are the 2 values of spin lock?
20. Explain atomic bit operation. Give 2 functions used in atomic bit operations.

1
Indian Institute of Information Technology
Design and Manufacturing, Kancheepuram End Semester
Chennai 600 127, India 24-Apr-2018
An Autonomous Institute under MHRD, Govt of India Duration: 3 hrs
An Institute of National Importance Marks: 40
Computational Engineering

Roll No: Name:

0. Who discovered the C programming language

1 Light Dose
1 mark each

1. What is the output.

int a=2.3;
float b=3;
printf("%d %f\n",a,b);

2. Display the error message, if error, or display the output.

switch(2)
{
case 2: printf("2");
}

3. Display the error message, if error.

int a=2;
switch(a)
{
case a++: printf("2");
}

4. What is the output.

if(-1)
printf("-1");
else if(0)
printf("0");
else printf(" 1");

5. What is the output. If error, display the error message.

if(1);
printf("1");
else
printf("0");

6. What is the output. If error, display the error message.


for(int j=0; j<10; j >>1);
printf("%d",j);

7. Represent (1234)10 in base 3 system.

8. Assume 2’s complement system, what is the decimal equivalent of 111010.

9. What is the output.

int a[3]={1,2,3};
printf("%d %d",sizeof(a), sizeof(a[0]));

10. What is the output.

int a=31; int* b; b=&a;


printf("%d %x %d %x %x",a, &a,*b, b, &b);

11. What operator must be used between 15 and 7 so that the output is 15. Similarly, which operator
between 0 and 9 yields 0.

printf("%d %d", 15 7, 0 9);

12. Write the function prototype for the function addition() that takes three variables as arguments,
namely int, float, char.

13. How do you represent −0 and 255 in a 32-bit floating point format.

2
14. Display either the output or the error message.

int i=0;
switch(i)
{
case 0: i++;
case 1: for(;i<=5;++i);
case 2: printf("%d",i);

15. Rewrite the following code using IF-GOTO.

int i;
for(i=0; i<5; i++);
printf("%d",i);

2 Medium Dose
1.5 marks each
1. Perform −4 × 3 in 2’s complement system.

2. Trace the code (write the output of each statement) with respect to a = 32767, b = 1. Assume 2’s
complement system with wrap round for overflow/underflow.

short int a,b;


a=a+b;
b=a-b;
a=a-b;

3
3. Perform 100200 − 002101 in base 3 system. Clearly, mention all intermediate steps when you perform
bit-wise subtraction. Do NOT convert this number into any other system to perform this arithmetic.

4. Represent 17.65 in a 32-bit floating point representation.

4
5. Rewrite using only while statements.

if(a>=5)
printf("a >=5");
else if ( a >=3)
printf("a >=3");
else
printf("a is less than 3")

6. For the following code; on executing a.out, suppose the user enters the integer 1234 as the first input
followed by enter key, how many more inputs the user is expected to enter to complete the task. Justify
your answer.

int a,b,c,d;

scanf("%1d %1d %1d %2d", &a, &b, &c, &d);

printf("%d %d %d %d \n",a,b,c,d);

7. What is the output. Justify.

void main()
{
function(0);
}

function(int a)
{
if(a==3)
return;

a++;
function(a);
printf("%d ",a);
}

5
8. Rewrite using IF-ELSE.

int c;
switch(c)
{
default: printf("default");
case 1:
case 2:
case 3: printf("3"); break;
case 4: printf("4"); break;

9. Justify the output of the code.

printf("%d",printf("hello")+printf("world"));

int a,b,c;

printf("\n%d",scanf("%d %d",&a,&b)+scanf("%d",&c));

10. How do you compute the length of a string (char array) using just one printf statement. Note: if you
use printf inside printf, then it is treated two printf statements.

6
3 Strong Dose
2 marks each
1. What is the output of the following two programs. Are they equivalent. Justify.

for(int i=1; ; i<<1)


{
printf("%d", i^15);

if(i ^ 15 == 0)
break;
printf("%d ", i);

for(int i=1; ; i<<1)


{
printf("%d", i^15);

if((i ^ 15) == 0)
break;
printf("%d ", i);
}

2. What is the order of the evaluation. Clearly mention the order and the output of each stage.

5 + 3 >> 2 < 0 << 14 - 6 * 2 && 4 * 3 + 3 & 11

7
3. In a 32-bit float pointing system, how many float numbers are there between two integers 2 and 3
(including 2 and 3).

4. What is the value of c, d, and e. Justify.

int j,c=1,d=1,e=1;

for(int i=1; i<=256; i=i*2)


{ j=1, d=1, e++ ;
while(j<=256)
{ j=j*3;
c++, d++;
}
}
printf("%d %d %d",c,d,e);

8
5. Mention all intermediate steps and the output of the following code.

int x;
printf("%d %d %d %d %d %d", x=x+2, x>>2, x++, x=x*2, x!=0, x=21<<1*2);

Extra Credits: (2+2+2=6 marks) Write a logic for both the questions and a C program for any one
question. Let your presentation be neat.
Q1: You are given 10 boxes, each filled with coins, and an electronic balance. Note that the electronic
balance has exactly one weighing plate and if you keep x coins on the plate, the display will tell you the
weight of those x coins. The coins are of two types; one weighing 1 gram and the other weighing 1.1 grams.
It so happens that out of 10 boxes, exactly one box is such that all coins in it are 1.1 grams and for all other
boxes, all coins are 1 gram. What is your logic to find out the ’odd box’ (box with 1.1 g coins). You must
access the electronic scale the minimum number of times (the least number possible) to answer this question.

Q2: You are given an integer array of very large size, say k. The array is such that the elements are
in increasing order until some location and after that all other locations are filled with the integer 32767.
For example, if k = 106 , say until 104 , the elements are in increasing order and between 104 + 1 and 106 the
array contains 32767 in each location. Assume that 32767 does not appear in 1 to 104 . Your task is to find
the very first appearance of 32767 without using k as part of the computation. No statement can make use
of the value of k. Let your logic be efficient.

9
Indian Institute of Information Technology
Design and Manufacturing, Kancheepuram
Quiz 1
Chennai 600 127, India
Duration: 1hr
An Autonomous Institute under MHRD, Govt of India
Marks: 15
An Institute of National Importance
COM - Computational Engineering

Roll No: Name:

Sampling text
Pixel Mp4
1. (1.5 marks) Match the following
ASCII Mp3
Frames jpeg

2. (2 marks) Draw the Human computational model. For each biological part of the body, mention one
analogous electronic component.

3. (2 marks) Represent the decimal numbers (i) 129 (ii) −63 in base 4 system.
4. (2 marks) Represent the decimal numbers (i) 12.75 (ii) 12.74 (iii) −12.74 (iv) 0.0 in binary. Assume 3
bit approximation to represent fractions.

5. (1+2=3 marks) Perform: (128)10 − (1)10 − (17)8 − (2E)16 . Clearly mention intermediate steps.

2
6. (2 marks) Multiply: (222)3 with (222)3 . Clearly mention intermediate steps.

7. (2.5 marks) Given a decimal number x, how many bits are required to represent x in binary. For
example, the binary equivalent of 4 is 100 which requires 3 bits. Justify your answer. How many bits
are required if x is a negative number.

3
Indian Institute of Information Technology
Design and Manufacturing, Kancheepuram
Quiz 2
Chennai 600 127, India
Duration: 1hr
An Autonomous Institute under MHRD, Govt of India
Marks: 15
An Institute of National Importance
COM - Computational Engineering

Roll No: Name:

0. (0 marks) Who is the first women computer scientist

1. (2 marks) What is the range of integers that can be represented in a 5-bit signed magnitude binary
system. In this system, perform (i) 13+7 (ii) -13-4

2. (2 marks) Represent (i) 127.175 in a 32-bit floating point format (ii) 32 in 2’s complement system
(iii) -32 in 2’s complement system
3. (1.5 marks) What is the output. Justify.

int a=1,b=2,c,d;
float x=5.0,y=6.0,w,z;
printf("%d %d \n", a,b);
printf("%f %f \n", x,y);
printf("%d %d \n", w,z);
printf("%f %f \n", c,d);

4. (1.5 marks) Rewrite the following using IF-ELSE structure without compromising on the underlying
logic.

int a;
switch(a+2)
{
case 49: { printf("the value of this case is %d", 49);
break;
}
case 48: printf("the value of this case is %d \n", 48);
printf("case without break st");
default: printf("i am in default case");
}

5. (1.5 marks) Identify all errors in this code.

int a=1;
switch(a)
{
case 1: printf("case label is 1");

case 0: printf("case label is 0");

case a>5: printf("case with comparison operator");

case (7||1): printf("case with logical operator");

case (2==5): printf("case with equality operator");

case printf("ab"): printf("case with printf");

2
6. (1.5 marks) The following code extracts the first three digits and the last three digits of an integer
variable p. Complete the code. Do NOT add additional instructions.
printf("the first 3 digits= , the last 3 digits= ," , )

7. (1.5 marks) A user enters an integer. Can we get the number of digits entered using just printf/scanf
statements. If so, write the code using printf/scanf statements. You should not use selection/repetition
statements. If not possible, give a justification.

8. (1 mark) What is the output. Justify.

if(a==5);
{
printf("the value of a is %d", 5);
printf("inside if");
}
else;

9. (1 mark) What is the output. Justify.

printf("output");
printf("\b\b");
printf("erform");
printf("\r\trmer");

10. (1.5 marks) Complete the code.

float a=127.127
printf("the value of a in 6.5 format is ",a);

printf("the integer part of a is ", );

printf("the value of a in 18.5 format prefixed with zeros is ", );

3
Extra Credit (3 marks): Consider the base r system. (i) What is the range of numbers in decimal
represented by this system in (a) signed system (b) 1’s complement system (c) 2’s complement system. (ii)
Given an integer n, how many bits do you need to represent n in all of the above three systems. Express as
a function of n and r.

4
Indian Institute of Information Technology
Design and Manufacturing, Kancheepuram
Quiz 2
Chennai 600 127, India
Duration: 1hr
An Autonomous Institute under MHRD, Govt of India
Marks: 15
An Institute of National Importance
COM - Computational Engineering

Roll No: Name:

0. (0 marks) Who is the first women computer scientist: Ada Lovelace

1. (2 marks) What is the range of integers that can be represented in a 5-bit signed magnitude binary
system. In this system, perform (i) 13+7 (ii) -13-4
Soln: Range: -16 to 15. 13+7 = 01101 + 00111 = 10100, -13-4 = 11101 + 10100 = 10001

2. (2 marks) Represent (i) 127.175 in a 32-bit floating point format (ii) 32 in 2’s complement system
(iii) -32 in 2’s complement system
Soln: (i) Sign bits: 0, Exponent: 0000110 , Mantissa: 11111100101100110011001

32= 0100000 (7 bits) , for positive numbers, no need to compute 2’s complement OR 2’s comple-
ment of a positive number is just its binary repn.

-32: 1’s compl of (0100000)=(1011111), 2’s compl (1011111)=1100000

3. (1.5 marks) What is the output. Justify.

int a=1,b=2,c,d;
float x=5.0,y=6.0,w,z;
printf("%d %d \n", a,b); // output: 1 2
printf("%f %f \n", x,y); // output: 5.000000 6.000000
printf("%d %d \n", w,z); // output: either junk or some content from integer pipe
printf("%f %f \n", c,d); // output: either junk or some content from float pipe

4. (1.5 marks) Rewrite the following using IF-ELSE structure without compromising on the underlying
logic.

int a;
switch(a+2)
{
case 49: { printf("the value of this case is %d", 49);
break;
}
case 48: printf("the value of this case is %d \n", 48);
printf("case without break st");
default: printf("i am in default case");
}

if(a+2==49)
{ printf("the value of this case is %d", 49);
break;
}
else if(a+2==48)
{ printf("the value of this case is %d \n", 48);
printf("case without break st");
printf("i am in default case");
}
else
printf("i am in default case");

5. (1.5 marks) Identify all errors in this code.

int a=1;
switch(a)
{
case 1: printf("case label is 1");

case 0: printf("case label is 0");

case a>5: printf("case with comparison operator"); // Error: integer constant expected,
//variable cannot be used

case (7||1): printf("case with logical operator"); // case 1, duplicate case label

case (2==5): printf("case with equality operator"); // case 0, duplicate case label

case printf("ab"): printf("case with printf"); // Error: integer constant expected

6. (1.5 marks) The following code extracts the first three digits and the last three digits of an integer
variable p. Complete the code. Do NOT add additional instructions.
printf("the first 3 digits= , the last 3 digits= ," , )

Assuming: 6 digits, then

printf(the first 3 digits=%d, the last 3 digits=%d,",p/1000,p%1000) }

In general,

printf(the first 3 digits=%d, the last 3 digits=%d,", p/(pow(10,log(10,p)-3)), p%1000) }

7. (1.5 marks) A user enters an integer. Can we get the number of digits entered using just printf/scanf
statements. If so, write the code using printf/scanf statements. You should not use selection/repetition
statements. If not possible, give a justification.

2
printf("enter an integer");
scanf("%d",&a);
printf("%d%n",a,&num);
printf("%d",num); // num stores the no of digits in a

printf("enter an integer");
scanf("%d",&a);
printf("no of digits=%d",printf("%d",a));

8. (1 mark) What is the output. Justify.

if(a==5);
{
printf("the value of a is %d", 5);
printf("inside if");
}
else; // ERROR: else with no if statement, NOTE: there is a semicolon after the previous if

9. (1 mark) What is the output. Justify.

printf("output");
printf("\b\b"); // cursor is at ’u’
printf("erform"); // outperform
printf("\r\trmer"); // cursor moves to the front and jumps to 9th place (tab offers 8 white spaces)
prints outperformer

10. (1.5 marks) Complete the code.

float a=127.127
printf("the value of a in 6.5 format is %6.5f ",a);

printf("the integer part of a is %3.0f ", a );

printf("the value of a in 18.5 format prefixed with zeros is %018.5 ", a );

3
Extra Credit (3 marks): Consider the base r system. (i) What is the range of numbers in decimal
represented by this system in (a) signed system (b) 1’s complement system (c) 2’s complement system. (ii)
Given an integer n, how many bits do you need to represent n in all of the above three systems. Express as
a function of n and r.
Hint: 1 How do you define 1’s complement and 2’s complement in base r system. As such it is defined
only for binary system.

Hint: 2 Try using logarithmic functions (with floor/ceil) to express the number of bits. Check are you
getting logr (n) + 1 or logr (n) + 2 with appropriate ceil/floor functions.

4
C Programming Practice - Test 2

Instructions:
1. All questions given here can be answered based on the concepts discussed in class. Therefore, Do NOT
use built-in functions and other features of C programming.
2. Duration: 14.00 to 17.00. You should mail your programs to [email protected] before
17.15. NO evaluation during the test hours.
3. Plagiarism check will be done for all programs and hence refrain yourself from copying.
4. You are free to use any online resources.
1. A teacher conducts a monthly test for a group of 4 students. There are 3 subjects with maximum
marks being 10 for each. Write a C program to answer the following. Your program must work for all
valid inputs and throw an error if invalid input is given.

(a) (1+2.5=3.5 marks) Variable declaration and Input acceptance: Ask the user to input marks of 3
subjects for 4 students. Must throw an error for invalid inputs. Marks with fractions are allowed
with at most one digit after the dot. Marks such as 3, 3.5 (exactly one digit after the dot is
allowed) are valid, whereas 3.45, 3.21 are invalid. Note that 3.20 is valid as it will be treated as
3.2.

(b) (1 mark) Computer Average for each subject for 4 students.

(c) (1.5 marks) Grade the students on all 3 subjects as per the following scheme. Grade S if marks
is at least twice the average. Grade A if marks is at least average+3 and below the cut off of ’S’.
Grade B if marks is exactly the average. Otherwise Grade C.

(d) (1+1.5+1.5=4 marks) Compute total marks for each student. Also, print the floor and ceil value
of the total without using floor/ceil functions.

2. Accept from the user 10 integers and a special integer x. Question: Check whether there exist a pair
of integers y and z in the input whose sum is x, i.e., x = y + z. Additionally, print all such pairs.
Logic: (3 marks) Write the logic below and trace your logic for the input; {1, 2, 3, 4, 5, 6, 1, −1, 0, −59},
x = 1. Further, write C program that implements this logic. (7 marks= variable declaration (1 mark),
logic (4 marks), printing all pairs (2 marks)).

1
C Programming Practice - Test 2

Instructions:
1. All questions given here can be answered based on the concepts discussed in class. Therefore, Do NOT
use built-in functions and other features of C programming.
2. Duration: 14.00 to 17.00. You should mail your programs to [email protected] before
17.15. NO evaluation during the test hours.
3. Plagiarism check will be done for all programs and hence refrain yourself from copying.
4. You are free to use any online resources.
1. Three students are participating in a carnatic music competition and they are evaluated on an integer
scale of 5 (0 to 5). There are three rounds of evaluation. Write a C program to answer the following.
Your program must work for all valid inputs and throw an error if invalid input is given.

(a) (1+1.5=2.5 marks) Variable declaration and Input acceptance: Accept the scores of each student
for each round. Throw an error if invalid input.

(b) (3 marks) For each round, students are graded as per the following scheme. Score= 4 or 5, then
Grade S, Score= 2 or 3, then Grade A, otherwise grade B. Grading must be implemented using
Switch-case and not by if-else.

(c) (3 marks) A student gets a title ’carnatic singer’ if he/she has secured at least one ’S’ or at least
two ’A’ in three rounds. Display all carnatic singers among three students.

(d) (1.5 marks) Compute average marks for each student over three rounds.

2. Accept from the user 10 integers. Question: For each element, print the multiplicities, the number of
times the element appears in the input.
Logic: (3 marks) Write the logic below and trace your logic for the input; {1, 2, 3, 4, 5, 6, 1, −1, 0, −59}.
Further, write C program that implements this logic. (7 marks= variable declaration and input accep-
tance (2 marks), logic (5 marks)).

1
C Programming Practice - Test 3
Mail your programs to [email protected] before 17.15.
1. Write a C program to perform the following;
(a) (2 marks) Accept a sequence of characters and special characters from the user. Special characters
can be any character that you find in Keyboard letters 1 to 0 (shift 1 gives !, shift 2 gives @...).
(b) (2 marks) Count the number of special characters in the input and display the count.
(c) (2 marks) For each character read, print the character along with its ascii value.
(d) (4 marks) Using a recursive function print all the characters read in reverse order.
2. (4:logic + 6:code) Write a C program to perform the following; Input: integer x, Output: Print x2
prime numbers. Your program must contain (i) at least one function apart from main() (ii) function
must have a return statement returning an integer/array.

C Programming Practice - Test 3


Mail your programs to [email protected] before 17.15.
1. Write a C program to perform the following;
(a) (2 marks) Accept a sequence of characters and special characters from the user. Special characters
can be any character that you find in Keyboard letters 1 to 0 (shift 1 gives !, shift 2 gives @...).
(b) (2 marks) Count the number of special characters in the input and display the count.
(c) (2 marks) For each character read, print the character along with its ascii value.
(d) (4 marks) Using a recursive function print all the characters read in reverse order.
2. (4:logic + 6:code) Write a C program to perform the following; Input: integer x, Output: Print x2
prime numbers. Your program must contain (i) at least one function apart from main() (ii) function
must have a return statement returning an integer/array.

C Programming Practice - Test 3


Mail your programs to [email protected] before 17.15.
1. Write a C program to perform the following;
(a) (2 marks) Accept a sequence of characters and special characters from the user. Special characters
can be any character that you find in Keyboard letters 1 to 0 (shift 1 gives !, shift 2 gives @...).
(b) (2 marks) Count the number of special characters in the input and display the count.
(c) (2 marks) For each character read, print the character along with its ascii value.
(d) (4 marks) Using a recursive function print all the characters read in reverse order.
2. (4:logic + 6:code) Write a C program to perform the following; Input: integer x, Output: Print x2
prime numbers. Your program must contain (i) at least one function apart from main() (ii) function
must have a return statement returning an integer/array.

1
C Programming Practice - Test 1 (29/Jan/2018)

Instructions: (i) For all, experiment your answer with the system before you present your solution in the
space provided. (ii) You are free to use internet/online resources. (iii) Discuss with me/TAs if clarity is
missing in any of the questions.

Roll No: Name:


1. (1.5 marks) Assume that the current directory is /home/iiitdm. Create three folders named F1 F2 F3
in a single command and verify whether it is created.

2. (1.5 marks) Create a word document, excel sheet, power point in F1, F2, F3, respectively. Verify
whether it is created.

3. (1.5 marks) How do you merge two pdf files stored in the current directory.

4. (1.5 marks) How do you restore the file that is deleted temporarily.

5. (1.5 marks) Assume you are in /home/iiitdm. How do you copy all text and ppt files in F1 to F2 in a
single command without actually moving to F1.

1
6. (2 marks) Assume you are in /home/iiitdm. Mention three different ways of moving all text files in F1
to F2.

7. (1.5 marks) How do you list all files that start with a substring 2018.

8. (1.5 marks) Create three text files in the current folder and compress them to create a .zip file.

9. (2 marks) How do you install calculator through command prompt.

10. (1.5 marks) How do you list all ppt files in the current and all its subfolders in a single command.
Assume the current folder is /home/iiitdm/

2
C Programming Practice - Test 1 (29/Jan/2018)

Instructions: (i) For all, experiment your answer with the system before you present your solution in the
space provided. (ii) You are free to use internet/online resources. (iii) Discuss with me/TAs if clarity is
missing in any of the questions.

Roll No: Name:

1. (1.5 marks) Assume that the current directory is /home/iiitdm. Create a .ppt file, .xls and .doc file.

2. (1.5 marks) Create three text files in the current directory and copy all three in a single command to
/home/iiitdm/labfolder

3. (1.5 marks) How do you merge three text files stored in the current directory.

4. (1.5 marks) How do you restore the file that is deleted temporarily.

5. (1.5 marks) Assume you are in /home/iiitdm. How do you copy all files that begin with a substring
cassignment in F1 to F2 in a single command without actually moving to F1.

1
6. (1.5 marks) How do you move a file from one folder to another without using mv command.

7. (2 marks) Assume you are in /home/iiitdm. Mention three ways of copying all doc files in F1 to F2.

8. (2 marks) How do you install adobe acrobat reader through command prompt.

9. (1.5 marks) Create three doc files in the current folder and compress them to create a .zip file.

10. (1.5 marks) How do you list all pdf files in the current and all its subfolders in a single command.
Assume the current folder is /home/iiitdm/

2
C Programming Practice - Test 1 (29/Jan/2018)

Instructions: (i) For all, experiment your answer with the system before you present your solution in the
space provided. (ii) You are free to use internet/online resources. (iii) Discuss with me/TAs if clarity is
missing in any of the questions.

Roll No: Name:


1. (1.5 marks) Assume that the current directory is /home/iiitdm. Create a folder named practicefolder
and verify whether it is created.

2. (1.5 marks) Create three word documents in /home/iiitdm and move all three to /home/iiitdm/practicefolder
in a single command. Verify whether it is created.

3. (1.5 marks) How do you merge three pdf files stored in the current directory.

4. (1.5 marks) Assume you are in /home/iiitdm. How do you move all files in F1 to F2 in a single
command without actually moving to F1.

5. (1.5 marks) How do you restore the file that is deleted temporarily.

1
6. (2 marks) How do you install gcc compiler through command prompt.

7. (1.5 marks) Create three ppt files in the current folder and compress them to create a .zip file.

8. (1.5 marks) How do you list all doc files in the current and all its subfolders in a single command.
Assume the current folder is /home/iiitdm/

9. (2 marks) Mention two ways of deleting a file permanently.

10. (1.5 marks) How do you copy all text files that begin with a substring filetxt and ppt files that begin
with a substring ppttxt from /home/iiitdm to /home/iiitdm/F1 in a single command.

2
Computational Engineering Practice - Test 1

Name: Roll No:


Instructions: Duration: 13.00 - 16.00. You are free to use internet. All programs must be answered using
sequence and selection statements only. Arrays, loops and built-in functions are not required to answer these
questions.
1. (8 marks) Given an integer (length is not given as part of the input), implement the following logic (i)
extract the digits at odd places and compute the sum (ii) extract the digits at even places and compute
the sum.
2. (12 marks) Given the marks of five subjects scored by a student; grade the student in each subject
following the scheme >= 90, Grade S, >= 80 < 90, Grade A, >= 70 < 80, Grade B, otherwise Grade
C. This must be done using (i) switch case and goto (ii) if-else and goto. You must use goto judiciously
and make your code compact. You get 6 points (3 pts each) if code is written without goto (relatively
longer code). you get 12 points (6 pts each) if code has goto in it and the code is compact.

3. (12 + 8 marks) Given an integer, the following tasks are expected from you (i) compute the length of
the integer (ii) check whether the length is 3k for some integer k (iii) If it is 3k , check whether the input
contains 3k identical digits, i.e., if k = 1, probable inputs are 333, 555, 777 and if k = 2, the probable
inputs are 111111111, 777777777, 999999999 (iv) if yes from Step (iii), then check whether the number
is divisible by 3k . Do you get yes at Step (iv) always ? Why is this logic work ? Justify your answer
below.

1
C Programming - Test 2 - Nov 13, 2018 - 13.00 - 16.00

Roll No: Name:

1. (7 marks) Write a C program to display ’Break fast Menu’ of Mon-Fri served in Akshaya Mess. The
details are available at institute website. Any format of display is fine.
2. (5+8=13 marks) Given a number, check whether a number is prime or composite. If it is composite,
display all its prime factors.
3. (10+5+5=20 marks) You are asked to distribute 30 balls among 5 boxes such that the box-2 contains
at least two balls, box-4 contains at least one and no constraints on other boxes. Note that other boxes
may contain ’0’ balls. The task is to display all possibilities of distributing the balls satisfying the
above constraint. Also display the count (the number of possibilities). Further, display the count (just
the count alone) using sequence statements only (no loop, no if).

———–

C Programming - Test 2 - Nov 13, 2018 - 13.00 - 16.00

Roll No: Name:

1. (7 marks) Write a C program to display ’Break fast Menu’ of Mon-Fri served in Akshaya Mess. The
details are available at institute website. Any format of display is fine.
2. (5+8=13 marks) Given a number, check whether a number is prime or composite. If it is composite,
display all its prime factors.
3. (10+5+5=20 marks) You are asked to distribute 30 balls among 5 boxes such that the box-2 contains
at least two balls, box-4 contains at least one and no constraints on other boxes. Note that other boxes
may contain ’0’ balls. The task is to display all possibilities of distributing the balls satisfying the
above constraint. Also display the count (the number of possibilities). Further, display the count (just
the count alone) using sequence statements only (no loop, no if).

———

C Programming - Test 2 - Nov 13, 2018 - 13.00 - 16.00

Roll No: Name:

1. (7 marks) Write a C program to display ’Break fast Menu’ of Mon-Fri served in Akshaya Mess. The
details are available at institute website. Any format of display is fine.
2. (5+8=13 marks) Given a number, check whether a number is prime or composite. If it is composite,
display all its prime factors.
3. (10+5+5=20 marks) You are asked to distribute 30 balls among 5 boxes such that the box-2 contains
at least two balls, box-4 contains at least one and no constraints on other boxes. Note that other boxes
may contain ’0’ balls. The task is to display all possibilities of distributing the balls satisfying the
above constraint. Also display the count (the number of possibilities). Further, display the count (just
the count alone) using sequence statements only (no loop, no if).

1
COM 101 Computational Engineering Practice - Test 1 - Feb 13, 2019

Instructions:
For all questions, get your answer verified from TAs as and when it is done. For Q1, write the necessary
commands in the space given. For Q2-Q4, you are expected to write a C program and show the output to
TAs. For Q4, present the logic in the space given and no need to write logic for Q2 and Q3.
1. (1+3=4 marks) Write linux commands in the space given. Task: In the current directory (assume:
/home/iiitdm), create a directory named ’testfolder’. Create three text files, three pdf files and three
ppt files in testfolder. Create a folder named ’copyfolder’ in the current directory (/home/iiitdm).
Present a linux command for the following
(a) (2+2=4 marks) From the current directory (/home/iiitdm), copy all text files in test folder to
copyfolder. Give two different commands to accomplish this task.

(b) (2+2=4 marks) From the current directory (/home/iiitdm), move all pdf files in test folder to
copyfolder. Give two different commands to accomplish this task.

(c) (2+2=4 marks) Merge all pdf files in copyfolder. Give two different commands to accomplish this
task.

2. Accept five integers from the user. Write a C program that will output
(a) (1 mark) the sum of five integers
(b) (1 mark) the average of five integers
(c) (1 mark) the number of odd numbers

1
(d) (1 mark) the number of negative numbers
(e) (2 marks) the number of integers ending with the digit ’7’
(f) (3 marks) the number of integers with the property that the third digit from the right is ’4’

3. (2+2+2=6 marks) Rewrite the following code using switch-case-goto (no if-else-goto). Do not write
the code here and you may key in on the system.

for(int i=0; i<=5; i=i+1)


for(int j=0; j<=2; j=j+1)
{ printf("%d %d", i,j);
if((i+j)%2==0)
printf("something");
}

4. (4 marks) Write a C program to print the following series upto 20 terms. 1 2 6 15 31 46 .... Write the
logic in the space given below and do not write the code. Key in the program on the system.

2
COM 101 Computational Engineering Practice - Test 1 - Feb 13, 2019

Instructions:
For all questions, get your answer verified from TAs as and when it is done. For Q1, write the necessary
commands in the space given. For Q2-Q4, you are expected to write a C program and show the output to
TAs. For Q4, present the logic in the space given and no need to write logic for Q2 and Q3.
1. (1+3=4 marks) Write linux commands in the space given. Task: In the current directory (assume:
/home/iiitdm), create a directory named ’testfolder’. Create three text files, three pdf files and three
xls files in testfolder. Create a folder named ’copyfolder’ in the current directory (/home/iiitdm).
Present a linux command for the following
(a) (2+2=4 marks) From the current directory (/home/iiitdm), copy all pdf files in test folder to
copyfolder. Give two different commands to accomplish this task.

(b) (2+2=4 marks) From the current directory (/home/iiitdm), move all xls files in test folder to
copyfolder. Give two different commands to accomplish this task.

(c) (2+2=4 marks) Merge all pdf files in copyfolder. Give two different commands to accomplish this
task.

2. Accept five integers from the user. Write a C program that will output
(a) (1 mark) the sum of five integers
(b) (1 mark) the average of five integers
(c) (1 mark) the number of non-negative numbers

1
(d) (1 mark) the number of single digit numbers
(e) (2 marks) the number of integers ending with the digit ’3’ or digit ’5’
(f) (3 marks) the number of integers with the property that the second digit from the left is ’3’

3. (2+2+2=6 marks) Rewrite the following code using switch-case-goto (no if-else-goto). Do not write
the code here and you may key in on the system.

for(int i=1; i<=10; i=i*2)


for(int j=0; j<=2; j=j+1)
{ printf("%d %d", i,j);
if((i*j)%2==0);
printf("if with a semicolon");
}

4. (4 marks) Write a C program to print the following series upto 20 terms. 1 2 6 16 44 126 .... Write
the logic in the space given below and do not write the code. Key in the program on the system.

You might also like