Printf() function in c programming
• In C programming language, printf() function is used to print the (“character, string, float, integer, octal and hexadecimal values”) onto the output screen.
• We use printf() function with %d format Specifier to display the value of an integer variable.
• Similarly %c is used to display character, %f for float variable, %s for string variable, %lf for double and %x for hexadecimal variable.
• To generate a newline, we use “n” in C printf() statement.
For Example:-
#include <stdio.h>
#include<conio.h>
int main()
{
char ch = ‘A’;
char str[20] = “myitschools.com”;
float flt = 10.234;
int no = 150;
double dbl = 20.123456;
printf(“Character is %c n”, ch);
printf(“String is %s n” , str);
printf(“Float value is %f n”, flt);
printf(“Integer value is %dn” , no);
printf(“Double value is %lf n”, dbl);
printf(“Octal value is %o n”, no);
printf(“Hexadecimal value is %x n”, no);
return 0;
}
Assignments:-
- Find area of circle
- Convert rupee to Paisa
- convert Celsius to Fahrenheit
- Show the avg of given three sujects marks
- Program to Add Two Integers
- Program to display the value of integers and float
- calculate simple interest
- Write a program to accept gross salary, where basic salary is 11000, DA is 12% and HRA is 14% of basic salary
- Calculate net pay amount, where price is 250 rupees, qty is 8 and discount given is on total amount is 4%.