Answers to Exercises in Udemy Course - 'C' Language for Beginners

These are the answers for exercises given in my Udemy course titled - C Language For Beginners.

Lesson 1 - Getting Started With Programming using C Language

Lesson 2 - Language Elements

Lesson 3 - Control Statements

Lesson 4 - Loops

Lesson 5 - Arrays

Lesson 6 - Chars and Strings

Lesson 7 - User-defined Functions

Lesson 8 - Pointers

Lesson 9 - Structures

Lesson 10 - Files

Lesson 11 - Binary Files

Lesson 12 - Miscellaneous Topics - Part 1

Lesson 13 - Miscellaneous Topics - Part 2

Additional Resources

Here are some additional videos that will help you to learn more.

My book C Language For Beginners is available at Amazon in Kindle Edition.

For my offline and online courses, please visit srikanthtechnologies.com

Lesson 1 - Getting Started With Programmming using C Language

Accept centimeters and display equivalent inches and millimeters

Accept price and quantity and display amount

Accept a number and display cube of the given number

Lesson 2 - Language Elements

Accept basic salary and calculate net salary by adding 40% HRA, 20% DA, and subtracting 5% PF

Accept two numbers and interchange them with and without using third variable.

Lesson 3 - Control Statements

Accept month number and year and display exact number of days in the given month.

Accept quantity and price from user and display net amount to be paid. Apply 20 % discount if quantity is more than 5 or 10% if quantity is more than 2. Apply additional 10% discount if total amount crosses 1000.

Accept marks from user and display grade based on the following table :

MarksGrade
>80A
>70B
>60C
<=60D

Accept three numbers and display the biggest of three numbers.

Accept marks in two subjects and display grade as follows:

Lesson 4 - Loops

Accept 10 numbers and display the biggest number

Accept a number and display whether it is a prime number

Accept base and power and display the result

Display table for number 9 from 10 to 20
           Sample Output : 
           9 * 10 = 90
           9 * 11 = 99
           …
           9 * 20 = 180

Display first 10 numbers in Fibonacci series

Accept two numbers and display GCD (Greatest Common Divisor)

Print sum of digits for numbers between 1000 and 9999

Lesson 5 - Arrays

Take an array of 10 elements, fill it with random numbers and then reverse array without using any second array.

Delete the element at the given position from an array of 10 elements and fill the last element with 0.

Read numbers from keyboard and copy them into an array of 5 elements. Make sure only positive numbers are copied into array and negative numbers are ignored.

Print all even numbers of an array of 10 elements first and then odd numbers.

Lesson 6 - Chars and Strings

Accept a string and count number of words

Accept 10 characters without echoing and print their inverse case

Accept password (without echoing characters) and check whether it has a digit, alphabet and special character – or @

Accept 10 strings and print the largest string

Print each word in a string in reverse order

Accept two strings and check whether they have same set of characters

Lesson 7 - Functions

Create a function that takes a number and returns 1 if number is prime, otherwise 0.

Create a function that takes an array of 10 integers and returns sum of the array.

Create a function that takes a string and a character and returns number of times the character is found in the string

Create a function that takes an array of 10 integers and returns highest number in the array

Create a function that takes two integers and returns GCD of the numbers

Create a function that takes an array of 10 integers and position of the element to be deleted, and delete the element from array. Fill last element of the array with 0.

Lesson 8 - Pointers

Create a function to take two numbers (int) and set both of them to the highest of two.

Create a function that takes an array of integers and sets all elements to zeros. Make function flexible so that it can work with an array of any size.

Create a function that returns the number of uppercase and lowercase letters in the given string. Hint: Use pass by reference to return two values from a function.

Write a program to find out how many times a substring is found in main string. Accept main string and sub string from keyboard.

Create a function to take two arrays of same size and copy second array to first array in reverse order.

Lesson 9 - Structures

Create a structure to represent a product with id, name, price and quantity on hand. Read details from user and print all details along with net price, which includes a tax of 18%

Create a function that takes two parameters of type struct product and return true if they match exactly, otherwise false.

Create a structure that stores time – hours, minutes, and seconds. Create an array of 5 elements of type struct time, read values from keyboard into array and then display them in HH:MM:SS format.

Create a function that takes a parameter of type struct time and return time after adding 1 second.

Lesson 10 - Files

Accept a filename and display all non-blank lines of the file.

Accept a filename and convert its contents to uppercase.

Accept a filename and display number of chars, words and lines in the file.

Assume a file marks.txt, which contains marks of students one per line. Display marks that are >= average marks.

Accept a filename and encrypt (add a number to ASCII code of each character) file and write encrypted content into another file with same primary filename, but .enc extension.

Lesson 11 - Binary Files

Create a file called marks.dat and write marks of students based on admission number. Marks of admno 1 will be written in first 4 bytes of file and then marks of admno 2 and so on. Accept marks from user in the order of admission number. Stop taking input when user enters -1.

Open marks.dat and display marks of student based on the given admission number. Hint: Use fseek() to position file pointer at the required position, based on admission number, before reading marks.

Accept two binary files and merge them into target file. Accept names of source files and target file from user.

Lesson 12 - Miscellaneous Topics - Part 1

Create a macro that takes an int and returns true if it is even number

Create a macro that takes a year and returns true if it is a leap year

Create enumeration that represents days of a week and use it in a switch statement to calculate wage. Wage depends on day of the week as follows: Mon – 1000, Tue – 1000, Wed – 1000, Thu – 1200, Fri – 1200, Sat – 1500, Sun – 1500

Lesson 13 - Miscellaneous Topics - Part 2

Accept a filename on command line and display how many alphabets, digits and special characters the file has.

Create a recursive function that takes number and prints digits in reverse order

Display sum of all numbers given as command line arguments

Accept number of students in a class and then take marks for all students. Display all marks in sorted order.