printf() and scanf() in C

In C language, input and output operations are performed by the functions printf() and scanf(), which are built-in library functions defined in the header file stdio.h.

printf() function

The printf() function prints a formatted output to the console. It can display different types of data, such as integers, characters, strings, floats, etc.

The syntax of the printf() function is:

printf("format string",argument_list);  

    The format string can be %d (integer), %c (character), %s (string), %f (float) etc.

    scanf() function

    The scanf() function is used for input. It reads the input data from the console.

    scanf("format string",argument_list);  

    Program to print cube of given number

    Let's see a simple example of c language that gets input from the user and prints the cube of the given number.

    #include<stdio.h>
    int main(){
    int number;
    printf("enter a number:");
    scanf("%d",&number);
    printf("cube of number is:%d ",number*number*number);
    return 0;

    Output

    enter a number:5
    cube of number is:125

    The scanf("%d",&number) statement reads integer number from the console and stores the given value in number variable.

    The printf("cube of number is:%d ",number*number*number) statement prints the cube of number on the console.

    Comments

    Popular posts from this blog

    Introduction To C

    First C Program

    Compilation process in c