print FUNCTION - Devbhoomi

FREE JOB ALERT & ONLINE TUTORIALS

Hot

Post Top Ad

Sunday 5 November 2017

print FUNCTION

printf() is used to display output.
Syntax :
printf ("format string", argument list);

format string : collection of escape sequence or/and conversion specification.
Argument list : contains a list of variables.

Example of scanf and printf :

    #include<stdio.h>
    int main()
    {
    char str[10];
    char ch;
    int i;
    float f;

    printf("Enter Character : ");
    scanf("%c",&ch); // Accept Character
    printf("\nCharacter is : %c ",ch);

    printf("\nEnter String : ");
    scanf("%s",str); // Accept String
    printf("\nString is : %s ",str);

    printf("\nEnter Integer : ");
    scanf("%d",&i); // Accept Integer
    printf("\nInteger is : %d ",i);

    printf("\nEnter Float : ");
    scanf("%f",&f); // Accept Float
    printf("\nFloat is : %f ",f);

    return 0;
    }



Explanation :
scanf will take the input as character (%c)string (%s)integer (%d)float (%f) and displays the output through printf statement by using conversion specification (%c, %s, %d, %f).
NOTE :
  • #include<stdio.h> is mandatory for printf function.
  • format specification of scanf and printf function must be enclosed in double quotes.
  • & ampersand is required in argument list of scanf function to be used with the list of variables.
  • The format specification and argument list must be separated by comma.

No comments:

Post a Comment

Post Top Ad