Home
Diploma Practice C Online People
Certificate Contact Us

Assignments on defining simple functions and calling them from main()

1. Write the following function:

   double getSphereVolume(double radius);

   This function takes the radius of sphere as parameter and returns the
   volume of sphere. Write a main() function to test this function. To test
   this function, in main() function read radius from the user and call this
   function. Finally print the value returned by this function.

   Note that, inside the getSphereVolume() function, you should not print the
   volume. This function should calculate and return the volume. Printing of
   volume should be done only from the main() function.

2. Write the following function:

   double getSphereSurfaceArea(double radius);

   Write the main() function to call and test the above function.

3. Write the following function:

   double getSphereWeight(double radius, double density);

   Write the main() function to call and test the above function.

4. Write the following function. This function sets the bit at the given
   position to one.

   unsigned int setBit(unsigned int val , int bitPos);

   Write the main() function to call and test the above function.
   In the main() function read an hexadecimal number from the user and also
   read bit position from the user. Call the above function. Print the value
   returned by that function in hexadecimal.

   Note that reading hex number and printing hex number allows us to check if
   the bit is set correctly or not.

5. Write the following function. This function clears the bit at the given
   position to zero.

   unsigned int clearBit(unsigned int val , int bitPos);

   Write the main() function to call and test the above function.
   In the main() function read an hexadecimal number from the user and also
   read bit position from the user. Call the above function. Print the value
   returned by that function in hex.

   Note that reading hex number and printing hex number allows us to check if
   the bit is cleared correctly or not.

6. Write the following function. This function returns total number of seconds
   elapsed at the given time 

   int getTotalSecondsElapsed(short hour, short min, short sec);

   Write the main() function to call and test the above function.

7. Write the following function. This function is same as function written in
   the above assignment. But takes structure Time as parameter. 
   Struct Time is specified in the assignments on structures. 

   int getTotalSecondsElapsed(struct Time t);

   Write the main() function to call and test the above function.

8. Write the following function. This function is reverse of previous
   function. It takes total seconds as input and returns struct time. 

   struct Time getTotalSecondsElapsed(int totalSeconds);

   Write the main() function to call and test the above function.





#401, Sai Sushma Homes, 23/A, S.R. Nagar Main Road, Hyderabad-500038, India.
Ph: +91-40-48508764, 7702028989, depik.help@gmail.com