Home
Diploma Practice C Online People
Certificate Contact Us

Assignments on writing advanced functions


1.  Write the following function: 

    int getLargestNum(int *nums, int count);

    This function takes an integer pointer (that is array address)  as first 
    parameter and size of array (i.e. number of integers in array) as second 
    parameter. This function should find and return the largest number
    present in the array.

    In the main() function, define an array of 5 integers, ask the user to 
    enter 5 integers. Read 5 integers into the array. Call the above
    function and print the largest number returned by the function.

2.  This assignment is same as above one, but main function is little bit
    different. In the main() function, define an array of 100 integers.
    First ask the user, how many numbers she/he wish to enter. Read this
    into a 'count' variable. The count must be less than 100, as our array
    size is 100. Read count of integers from the user and call the
    getLargestNum() function. Finally print the value returned by the function. 

3.  This assignment also same as first one. Only main() function is different.
    In the main() function, define a pointer to integer. Ask the user to enter
    count of numbers. Allocate memory for the count of integers dynamically
    by calling malloc() function. Store the allocated address in the pointer
    variable. Now read the count of numbers from the user into the
    dynamically allocated array. Call the getLargestNum() function and print 
    the value returned by that function.

4.  Write  the following function:

    int getCountofCapitalLetters(char *str);

    This function takes the char pointer (i.e. address array/string).
    This function should find the number of capital letters present in the
    string and return that count. Observe that here, function is not
    getting the length of the array/string. Why ?

    In the main() function ask the user to enter a line of text containing
    multiple words, with both lower case and upper case letters. Read the line 
    from the user. Call the above function by passing the line of text, that
    is string. Print the count of capitals returned by the function.
 
5.  Write  the following function:

    void convertToLowerCase(char *str);

    This function should convert all the capital letters present in the 
    given string into small (lower case) letters.

    In the main() function, read a line of text (not just one word) from
    the user and call the above defined function. After returning from the
    function, print the line. It should contain all the lower case letters.

6.  Write  the following function:

    void strcpyLowerCase(char *dst, char *src);

    This function copies the source string to the destination string. But while
    copying, converts all the upper case letters to the lower case letters.

    In the main() function define two strings. Read a line of text (not 
    just one word) from the user into first string. Call the above defined 
    function by passing both the strings. First string should be passed as 
    source string and second should be destination string. After returning 
    from the function, print both the first and second strings. 

7.  int getSecondsFrmTime(struct Time *tm);

    struct Time
    {
      int hour;
      int min;
      int sec;
    };

    This function takes the pointer to struct Time and returns the total number
    of seconds for the given time.

    In the main() function, define struct Time variable. Read hours, minutes
    and seconds into this structure. Call the above function by passing the
    address of this structure. Print the seconds returned by this function.

8.  void convertSecondsToTime(int seconds, struct Time *tm);

    This function takes the total number of seconds and pointer to struct Time.
    It converts the seconds into hours, minutes and seconds. And stores them
    in the Time structure.

    In the main() function, define seconds variable and struct Time variable.
    Read seconds from the user, call the function by passing seconds and
    address of struct Time variable. After returning from the function
    print the structure variable.

9.  void getStudentInfo(struct Student *ps);

    struct Date
    {
      char  date;
      char  month;
      short year;
    };

    struct Student
    {
      char  name[40];
      long long mobile;
      struct Date dob; //Date of birth, struct Date as given in assignment 2.
    };

    This function asks the user to enter Student information. Reads the
    informatino and  fills the structure, by using the structure pointer
    received as parameter.
 
    In the main() function, define a structure variable of type struct Student.
    Call the above function by passing the address of structure variable.
    After returning from the function, print the content of structure variable.

10. void printStudentInfo(struct Student *ps);

    This function simply prints the student information present in the
    given in structure.

    Keep this function and prevous function in assignment 9 also in the
    same file. In main() function define a structure variable of type
    struct Student. Call the getStudentInfo() function to read the 
    student information from the user. Next call this function
    printStudentInfo() to print the content of student structure.

11. void getTotalAvgMaxMin(int *marks, int *tot, int *avg, int *max, int *min);

    First parameter to this function is an array of marks. This marks array 
    size is 6. This size of array is assumed as contstant and not passsed as 
    parameter. The remaining four parameters are addresses of integer 
    variables. This function finds the total of marks, average of marks,
    maximum mark and minimum mark. It places all these values in the 
    corresponding addresses provided.

    In the main() function, define an integer array of size 6. Also
    define integer variables, totalMarks, averageMark, maxMark, and minMark.
    Read 6 subject marks from the user into marks array. Call the above
    function by passing array and addresses of all the four variables.
    After returning from the function, print the four variables.

12. void getTotalAvgMaxMin(int *marks, int *result);

    This function is similar to above function. Only difference is that
    the second parameter, result is also an array of size 4. The function
    finds the total, average, minimum mark and maximum mark, And writes them
    in the result array.

    In the main() function, define two arrays, one for six subjects marks,
    and another two get four results. Read the marks from the user and
    call the function, by passing marks and results array. After returning
    from the function, print the values in the results array.




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