Printf And Scanf Functions In C
In the C programming language, the "printf()" and "scanf()" functions play
crucial roles in handling input and output operations. Both functions are
part of the standard input-output library and are declared in the "stdio.h"
header file.
printf() Function
The printf() function is used for output, allowing you to display
information on the console.
Syntax:
printf("format string", argument_list);
The format string can include placeholders such as %d for integers, %c
for characters, %s for strings, %f for floats, and more.
Program:
#include<stdio.h>
int main(){
int num=6;
printf("The cube number of %d is :%d",num ,num*num*num);
return 0;
}
Output:
The cube number of 6 is :216
scanf() Function
On the other hand, the scanf() function is employed for input,
enabling the program to read data from the console.
Syntax:
scanf("format string", argument_list);
Program:
#include<stdio.h>
int main(){
int num;
printf("Enter the number:");
scanf("%d", &num);
printf("The cube number of %d is :%d",num ,num*num*num);
return 0;
}
Output:
Enter the number:20
The cube number of 20 is :8000
More topic in C