what is printf and scanf in C Programming

printf

It helps us to display message in the output.

Syntax:
printf("message");
Example:
#include<stdio.h>
main()
{
printf("HELLO");
}
OUTPUT: HELLO
#include<stdio.h>
main()
{
int n=1;
printf("%d",n);
}

OUTPUT: 1


scanf


Using scanf we can use our own values.

Syntax:
scanf("format specifier",&variable);
Example:
#include<stdio.h>
main()
{
int n;
printf("Select a number:\n");
scanf("%d",&n);
printf("Half of the number is:%d",n/2);
}

Output:
Select a number: 2
Half of the number is:1 

0 Comments