Z Code Writer is an Online Blog for beginner programmers. Here, you will find tech, build your Programming Skills and other Programming Languages like C, C++, HTML, JavaScript, Java Code, Web Designing and the University of Sialkot (USKT) CGPA / GPA Calculator, etc.

Showing posts with label define formatted output function with example. Show all posts
Showing posts with label define formatted output function with example. Show all posts

Tuesday, 16 July 2019

The printf() Function

The printf() Function

      The printf() function is used to display the output on monitor in a specified format. It is also called the formatted output function. It is most commonly used in C programs to display the output. This function is defined in the "stdio.h" header file.
The syntax of 'printf()' function is as follow:
            printf (format_string   [ ,   arguments ] ) ;


Write a program to compute and print the area of a square with given height and width. The formula to compute the area of square is

                               Area = height * width ;


Example in C


#include < stdio.h >
#include < conio.h >
void main ( )
{
      int   height , width , area ;
      height = 13 ;
      width = 5 ;
      area = height * width ;
      printf ( " Area of square is : %d " , area ) ;
}

Example in C++


#include < iostream >
using namespace std ;

int main ( )
{
      int   height , width , area ;
      height = 13 ;
      width = 5 ;
      area = height * width ;
      cout << " Area of square is : " << area ;
      return 0 ;
}