/**/ Practice Programs on printf, escape sequence and format specifiers in C Language - Dextutor

Practice Programs on printf, escape sequence and format specifiers in C Language

Programs on the use of:
• printf() function
• escape sequences (\t, \n, etc)
• format specifiers(%d %f etc.)

1. Alexandra works at Tech Innovations Hub in Silicon Valley, California, USA. He wants to create an address card to share with his friends. Write a C program that outputs the following details:

My Workplace: Tech Innovations Hub
Designation: Software Developer
Location: Silicon Valley

2. Write a C program to display the following output:

Welcome to the first lesson on C Language.
Next, we will learn about the history of C.

You must use only a single printf statement to achieve the above task.
Hint: Use newline character

3. Elena is coding a simple C program to highlight the day’s temperature. The expected output should be presented in the format:

"Today’s Temperature:    8"
“Tomorrow’s Temperature: 4”

Ensure that the output is exactly as shown above. The numbers 8 and 4 must be perfectly aligned. Write a C program to fulfil these requirements.

4. Aarav is exploring C programming and wishes to create a simple program to showcase a specific floating-point value. Help him write a program that declares a float variable named discountAmount with an initial value of 12.75. Subsequently, print the value of the discount amount using the printf function. Write a C program to fulfil this scenario.
Hint: Use %.2f to display the float value to 2 decimal places.

5. Priya is venturing into C programming and wants to create a basic program to display a specific character value. Assist her by writing a program that declares a char variable named grade initialized with the character ‘A’. Subsequently, print the value of the grade using the printf function. Write a C program to accomplish this task.

6. Mia is developing a C program that represents her profile with predefined values as 20 for age (an integer), 5.4 for height (a float), and ‘A’ for designation (a character). Assist her by writing a program that initializes these values and displays Mia’s profile using the printf function. Write a C program to implement this scenario.

7. Arun is working on a C program to display the total bill amount. Arun wants to ensure that the output includes double quotes around the total bill amount. Write a C program that initializes a variable amount to 26.50. Use the printf function to display the total bill amount, ensuring that it is enclosed in double quotes. The sample output is as follows:

Total Bill Amount: "$26.50"

8. Aditya is sharing information about a book. He wants to display the book’s title(character), the number of pages (integer), and the price (float) using a C program. Write a C program for Aditya that uses printf to display the book’s information. Use the following predefined values:

Sample Output:
Title : "U”
Pages: 150
Price : $12.99