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 %d\\n” , 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:-

  1. Find area of circle
  2. Convert rupee to Paisa
  3. convert Celsius to Fahrenheit
  4. Show the avg of given three sujects marks
  5. Program to Add Two Integers
  6. Program to display the value of integers and float
  7. calculate simple interest
  8. Write a program to accept gross salary, where basic salary is 11000, DA is 12% and HRA is 14% of basic salary
  9. Calculate net pay amount, where price is 250 rupees, qty is 8 and discount given is on total amount is 4%.