Declare & print variables - C Program

C Program to declare variables and print their values.

Solution:

In this program, we will declare both integer and floating type of variables.

We will also learn to print an output of the integer and float variables. Integer and float variable must be declared as int and float datatype respectively in local declaration part.

The syntax of printf statement is:

printf("format specifier", values);

Here, format specifier depends on the data type of the variable e.g int format specifier is %d, float specifier is %f etc.

#include <stdio.h>
void main()
{
    int a=5,b=14; // declaration of variables (integer types variables)
    float c=9.4, d=25.6; // declaration of variables (floating types variables)
    printf("Values of integer variables: \n");
    /*printing integer types of variables using format specifier (%d) */
    printf("%d\t %d \n", a,b);
    /*printing float types of variables using format specifier (%f) */
    printf("Values of floating variables: \n");
    printf("%f \n%f", c, d);  
}


Output:

declare variables print values