0% found this document useful (0 votes)
7 views2 pages

Lab Assignment 221024

j

Uploaded by

zoyan2705
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)
7 views2 pages

Lab Assignment 221024

j

Uploaded by

zoyan2705
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/ 2

Fall Session 2024-25

Course Name & Code: Computer Programming (CSE104)


Program & Sem: B.Tech 1st Sem
Section: D

Lab Assignment (Functions & Pointers)


1. Write a C program that invokes a function power(a, b ) to calculate and print the value
of a raised to b. Do not use any library function/operator.

2. Write a C program that takes a positive integer from the user and invokes a function
to compute and print the binary equivalent of the integer.

3. Write a C program that takes a positive integer from the user and invokes a function
to obtain the prime factors of this number. For example, prime factors of 24 are 2, 2, 2 and
3, whereas prime factors of 35 are 5 and 7.

3. Write a C program that invokes two functions for swapping the value of two variables.
The first function (swap_by_value) should demonstrate call by value principle while the
second function (swap_by_reference) should demonstrate call by reference principle. The
program should print the following in the given order:

a. Value of variables in main() before calling any function


b. Value of variables after swapping in swap_by_value function
c. Value of variables in main() after calling swap_by_value function
d. Value of variables after swapping in swap_by_reference function
e. Value of variables in main() after calling swap_by_reference function

4. Given three variables x, y, z write a C program that invokes a function to circularly


shift their values to right. In other words if x = 5, y = 8, z = 10, after circular shift x = 10,
y = 5, z = 8. Call the function with variables a, b, c to circularly shift values. The new
values of the variables should be printed in the main function after the function call.

5. A computer game to ascend a building with a specified number of floors. You have three
different facilities for each floor to reach the top: the elevator (1), the escalator (2), and
walking up the stairs (3).

Each facility has its own scoring rule. Assume the initial score is zero.

• Elevator (1): Score increments to the next even number.


• Escalator (2): Score increments to the next odd number.
• Walk (3): Score increments to the next prime number.

Example: If number of floors 4 and person chosen 3 for first floor, 2 for second floor, 3 for
third floor and 2 for fourth floor. The score is 2(first prime number) +1(first odd number)
+3(next prime number) +3(next odd number) =9.

Write a C program to display the score to ascend a building. Create different functions
for incrementing score according to the facility.

You might also like