0% found this document useful (0 votes)
21 views3 pages

C Program

HOW to learn c programing

Uploaded by

thanikad.ei24
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)
21 views3 pages

C Program

HOW to learn c programing

Uploaded by

thanikad.ei24
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/ 3

Write a C program that demonstrates the usage of different

format specifiers and options in the printf() function. The


program should perform the following tasks:
Print a string without any format specifiers.
Print an integer variable using the %d format specifier.
Print a character variable using the %c format specifier.
Print a float variable using the %f format specifier.
Print a hexadecimal number using the %x format specifier.
Print an octal number using the %o format specifier.
Use escape sequences like \n, \t, \a, \b, \f, \r, \v, \\, \', \", \? within
printf() statements.
Requirements
Declare and initialize the necessary variables for each task.
Use the appropriate format specifiers and options in the printf()
statements.
Ensure that the output is displayed correctly and follows the
specified format.
Example Output
This is a string.
Integer: 42
Character: A
Float: 3.140000
Hexadecimal: 1a
Octal: 77
Float (right-aligned, 2 decimal places): 3.14
Float (right-aligned, 4 decimal places): 3.1400
Float (left-aligned, 2 decimal places): 3.14
Hello
World
Hello\World
Hello"World"
Hello?World?
Hello
World
Hello\World

Write a C program that prompts the user to enter various types


of data and then displays the entered values using printf(). The
program should perform the following tasks:
Prompt the user to enter an integer and store it in a variable.
Prompt the user to enter a character and store it in a variable.
Prompt the user to enter a float and store it in a variable.
Prompt the user to enter a string (up to 20 characters) and store it in
a variable.
Prompt the user to enter an octal number and store it in a variable.
Prompt the user to enter a hexadecimal number and store it in a
variable.
After reading the input, the program should display the entered
values using printf() statements with appropriate format specifiers.
Requirements
Use the scanf() function to take input from the user.
Use printf() statements with format specifiers to display the entered
values.
Ensure that the output is displayed correctly, with each piece of
information on a new line.
Example Input
Enter an integer: 42
Enter a character: A
Enter a float: 3.14
Enter a string: Hello
Enter an octal number: 77
Enter a hexadecimal number: 1a
Example Output
Integer entered: 42
Character entered: A
Float entered: 3.140000
String entered: Hello
Octal number entered: 77
Hexadecimal number entered: 1a

You might also like